A Discord bot built on Cloudflare Workers that allows users to store and manage game codes (friend codes, referral codes, etc.) on a per-server basis.
- Store game codes - Save friend codes, referral codes, and other game-related codes
- Per-server storage - Each Discord server has isolated code storage
- Simple commands - Easy-to-use slash commands for managing codes
- Serverless architecture - Runs on Cloudflare Workers for global low-latency
- Persistent storage - Uses Cloudflare KV for reliable data persistence
- Runtime: Cloudflare Workers
- Framework: Hono
- Discord API: discord-interactions
- Storage: Cloudflare KV
- Language: TypeScript
- Package Manager: Bun
- Code Quality: Biome
- Bun installed
- A Discord Application with bot enabled
- A Cloudflare account with Workers access
-
Clone the repository
git clone https://github.com/nurodev/pokecode-discord-bot.git cd pokecode-discord-bot -
Install dependencies
bun install
-
Configure environment variables
Create a
.envfile in the root directory:BACKUP_AUTH_TOKEN="your_backup_auth_token" DISCORD_BOT_TOKEN="your_discord_bot_token" DISCORD_CLIENT_ID="your_discord_client_id" DISCORD_PUBLIC_KEY="your_discord_public_key"Get your Discord public key from the Discord Developer Portal.
-
Register Discord commands
Run the
registerscript to register the bot's slash commands with Discord:bun run register
Start the local development server:
bun devThe bot will be available at http://localhost:8787. Configure this URL as your Discord bot's Interactions Endpoint URL during development (you may need to use a tunnel like ngrok).
bun check # Run linting and formatting checks
bun lint # Auto-fix linting issues
bun format # Auto-format codeDeploy to Cloudflare Workers:
bun deployAfter deployment, update your Discord bot's Interactions Endpoint URL in the Discord Developer Portal to your Cloudflare Worker URL (e.g., https://your-worker.your-subdomain.workers.dev/interactions).
The bot provides a single /code command with three subcommands:
/code list
Displays all your saved codes for the current server.
/code list user:<@user>
Displays all saved codes for the mentioned user in the current server.
/code add name:<label> code:<your-code>
Adds a new code with a custom label. Duplicate names are not allowed.
/code remove name:<label>
Removes a code by its label.
Data is stored in Cloudflare KV with the following structure:
- Key pattern:
user_codes/{guild_id}/{user_id} - Value: Array of code entries with
nameandcodefields
Each user's codes are isolated per Discord server.
This project uses Biome for code formatting and linting. Please run bun check before committing changes to ensure code quality standards are met.
MIT