Host your discord bot on Cloudflare with basic AI commands using Cloudflare Workers AI.
- Create a new discord application in your Discord Portal
- Navigate to the
Bot
settings on the left sidebar, or go tohttps://discord.com/developers/applications/<application-id>/bot
- Copy your discord application token to set as your environment variable later
- Navigate to the
OAuth2
settings - Enable the following permissions under
OAuth2 URL Generator
SCOPES
- [x] bot
- [x] applications.commands
BOT PERMISSIONS > TEXT PERMISSIONS
- [x] Send Messages
- [x] Use Slash Commands
- Copy and navigate to the
GENERATED URL
and go through the OAuth flow - Find your guild and channel ids by right-clicking a discord channel and copying the link, e.g.
https://discord.com/channels/<DISCORD_GUILD_ID>/<DISCORD_CHANNEL_ID>
- Clone repository, install
pnpm
, install dependencies
npm install -g pnpm
pnpm install
- Register all slash commands
pnpm run register
- Create a
.dev.vars
populated with the necessary environment variables:
CLOUDFLARE_ACCOUNT_ID=...
CLOUDFLARE_API_TOKEN=...
CLOUDFLARE_WORKERS_GATEWAY_ID=...
DISCORD_TOKEN=...
DISCORD_PUBLIC_KEY=...
DISCORD_APPLICATION_ID=...
DISCORD_GUILD_ID=...
DISCORD_CHANNEL_ID=...
- Create a new Cloudflare Worker and pass these environment variables in the
Variables and Secrets
section of your worker dashboard - After pushing changes and successful deployment via GitHub Actions, set your Cloudlfare Worker URL, e.g.
<worker-name>.<subdomain>.workers.dev
, as your Discord app'sINTERACTIONS ENDPOINT URL
and save - Try using the
/hello
command in your channel
- Start wrangler
pnpm run dev
- Tunnel localhost to live, accessible URL endpoint
pnpm run tun
- Set the tunnel URL as your Discord app's
INTERACTIONS ENDPOINT URL
and save - Try using the
/hello
command in your channel
Feel free to ask me questions about this repository.
If you found this to be helpful, I would appreciate your support 🤗