Skip to content

NuroDev/pokecode-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



🤖

PokeCode Discord Bot

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.



Features

  • 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

Tech Stack

  • Runtime: Cloudflare Workers
  • Framework: Hono
  • Discord API: discord-interactions
  • Storage: Cloudflare KV
  • Language: TypeScript
  • Package Manager: Bun
  • Code Quality: Biome

Prerequisites

Setup

  1. Clone the repository

    git clone https://github.com/nurodev/pokecode-discord-bot.git
    cd pokecode-discord-bot
  2. Install dependencies

    bun install
  3. Configure environment variables

    Create a .env file 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.

  4. Register Discord commands

    Run the register script to register the bot's slash commands with Discord:

    bun run register

Development

Start the local development server:

bun dev

The 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).

Code Quality Commands

bun check              # Run linting and formatting checks
bun lint               # Auto-fix linting issues
bun format             # Auto-format code

Deployment

Deploy to Cloudflare Workers:

bun deploy

After 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).

Usage

The bot provides a single /code command with three subcommands:

List codes

/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.

Add a code

/code add name:<label> code:<your-code>

Adds a new code with a custom label. Duplicate names are not allowed.

Remove a code

/code remove name:<label>

Removes a code by its label.

Storage

Data is stored in Cloudflare KV with the following structure:

  • Key pattern: user_codes/{guild_id}/{user_id}
  • Value: Array of code entries with name and code fields

Each user's codes are isolated per Discord server.

Contributing

This project uses Biome for code formatting and linting. Please run bun check before committing changes to ensure code quality standards are met.

License

MIT

About

🤖 A Discord bot to store Pokemon Go friend codes

Topics

Resources

License

Stars

Watchers

Forks