Skip to content

Repository files navigation

Discord Bot

A Discord slash-command bot running on Cloudflare Workers. The /llm command acknowledges interactions immediately, generates an answer with Workers AI, and uses Cloudflare Workflows to deliver the deferred response reliably.

Discord slash command followed by a deferred Workers AI response

How it works

  1. The Worker verifies Discord's Ed25519 request signature and rejects stale requests.
  2. A per-user KV rate limit protects Workers AI inference from sustained abuse.
  3. Discord receives a deferred response before its interaction deadline.
  4. Workers AI generates the answer outside the request path.
  5. A Workflow patches the original Discord message, with retries and a ten-minute timeout.

The model is selected with AI_MODEL and defaults to @cf/qwen/qwen3.8-27b. Responses are capped at Discord's 2,000-character message limit.

Development

npm install
npm run dev

Set the Discord application public key for local or deployed request verification:

npx wrangler secret put DISCORD_PUBLIC_KEY

The Worker also needs the AI, WORKFLOW, and RATE_LIMITS bindings declared in wrangler.toml.

Checks

npm run typecheck
npm run lint
npm run test:run
npm run format:check

Deploy

npm run deploy

After deployment, set the Worker's URL as the Discord application's Interactions Endpoint URL.

Releases

Packages

Used by

Contributors

Languages