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.
- The Worker verifies Discord's Ed25519 request signature and rejects stale requests.
- A per-user KV rate limit protects Workers AI inference from sustained abuse.
- Discord receives a deferred response before its interaction deadline.
- Workers AI generates the answer outside the request path.
- 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.
npm install
npm run devSet the Discord application public key for local or deployed request verification:
npx wrangler secret put DISCORD_PUBLIC_KEYThe Worker also needs the AI, WORKFLOW, and RATE_LIMITS bindings declared
in wrangler.toml.
npm run typecheck
npm run lint
npm run test:run
npm run format:checknpm run deployAfter deployment, set the Worker's URL as the Discord application's Interactions Endpoint URL.
