Serverless Discord bot in webhook mode to quickly interface with BingAI a.k.a Sydney's using a reversed engineered API.
This is much slower than ChatGPT variants as there is no way to disable streaming mode (words generate one at a time) and I have to capture when the stream ends.
Note: This is mainly for personal use, if you would like to add features, do fork the repository. Do perform PRs back if you would be so kind!
- A Cloudflare account with Workers (at least free-tier) enabled
- Completed the Discord Developers - Getting Started - Creating an App with the same scopes and have added the bot to your target server
- Logged in to Bing and grabbed the request cookie to https://edgeservices.bing.com/edgesvc/turing/conversation/create
- Make sure a Success message is shown before grabbing the cookie
- You can use your Browser's Developer Tools to extract this when visiting https://edgeservices.bing.com/edgesvc/turing/conversation/create
- You likely need to periodically update this after it expires
- Sign in to https://www.bing.com/ on the browser
- Clone this repository
- Run
npm ci
oryarn install
- Replace
{DISCORD_TOKEN}
and{DISCORD_APPLICATION_ID}
in the followingDISCORD_TOKEN={DISCORD_TOKEN} DISCORD_APPLICATION_ID={DISCORD_APPLICATION_ID} npx node src/register.js
and run it to register the bot commands - Run
npx wrangler secret put DISCORD_APPLICATION_ID
and set the Discord app's ID - Run
npx wrangler secret put DISCORD_PUBLIC_KEY
and set the Discord app's public key - Run
npx wrangler secret put DISCORD_TOKEN
and set the Discord bot's token - Run
npx wrangler secret put BING_COOKIE
and set your latest Bing cookie request header on https://edgeservices.bing.com/edgesvc/turing/conversation/create - Add space-delimited user IDs to whitelist in
DISCORD_USERID_WHITELIST
in wrangler.toml - (Optional) To enable context, run
npx wrangler kv:namespace create session
and replace the ID ofBINGAI_SYDNEY_DISCORD_BOT_KV
wrangler.toml, else removekv_namespaces
block entirely from wrangler.toml - (Optional) Choose your
BING_CONVERSATION_STYLE
by commenting and uncommenting accordingly in wrangler.toml - (Optional) Update
BING_BEHAVIOR
in wrangler.toml with your desired behavior / system message - Run
npx wrangler publish
to deploy to Cloudflare Workers - Set the
Interactions Endpoint URL
of your Discord application to the URL of the deployed worker
- Sign in to https://www.bing.com/ on the browser
- Run
npx wrangler secret put BING_COOKIE
and set your latest Bing cookie request header on https://edgeservices.bing.com/edgesvc/turing/conversation/create