+
Skip to content

imgta/discord-cf-worker

Repository files navigation

Discord Cloudflare Deployment

Host your discord bot on Cloudflare with basic AI commands using Cloudflare Workers AI.

Discord App Setup

  1. Create a new discord application in your Discord Portal
  2. Navigate to the Bot settings on the left sidebar, or go to https://discord.com/developers/applications/<application-id>/bot
  3. Copy your discord application token to set as your environment variable later
  4. Navigate to the OAuth2 settings
  5. 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
  1. Copy and navigate to the GENERATED URL and go through the OAuth flow
  2. 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>

Quick Start

  1. Clone repository, install pnpm, install dependencies
npm install -g pnpm
pnpm install
  1. Register all slash commands
pnpm run register
  1. 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=...
  1. Create a new Cloudflare Worker and pass these environment variables in the Variables and Secrets section of your worker dashboard
  2. 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's INTERACTIONS ENDPOINT URL and save
  3. Try using the /hello command in your channel

Local Testing

  1. Start wrangler
pnpm run dev
  1. Tunnel localhost to live, accessible URL endpoint
pnpm run tun
  1. Set the tunnel URL as your Discord app's INTERACTIONS ENDPOINT URL and save
  2. Try using the /hello command in your channel

Support

Feel free to ask me questions about this repository.
If you found this to be helpful, I would appreciate your support 🤗

About

Discord bot deployed on Cloudflare Workers, with AI text and image generation slash commands.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载