Discord Bot

Overview & Setup

A Python discord.py 2.x bot with an embedded FastAPI server. It runs the community's economy, contracts and missions, and serves the private API the KSP mod talks to.

Install & run

Create a virtual environment, install dependencies, copy the example environment file and fill in your secrets.

Terminal
cd "BM Discord Bot"
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env   # fill in DISCORD_TOKEN, FIREBASE_CREDENTIALS, GEMINI_API_KEY

# Normal start (no slash command sync):
python bot.py

# After adding or changing slash commands:
python bot.py --sync

Only sync when commands change

Pass --sync only when slash commands have actually changed. Repeated syncing hits Discord’s rate limit.

Configuration files

config.py

from config import cfg

Singleton holding all secrets and runtime config, loaded from .env at import time. Imported everywhere as cfg.
settings.py

balance values

Gameplay tuning: XP rates, cooldowns, economy constants, channel and role IDs. Safe to commit; no secrets.
.env

secrets

DISCORD_TOKEN, FIREBASE_CREDENTIALS, GEMINI_API_KEY and friends. Never committed.

Cogs

Every feature is a discord.py Cog under cogs/. Cogs never import each other directly; they communicate through the shared store and settings modules.

Command grouping

When COMMAND_GROUP is set (default b), all commands nest under that group, such as /b help, /b balance, and so on. Administrator commands live under a top-level admin group; moderation under mod.