Casino bot is a gambling discord bot I made for my friends.
It is able to play blackjack, slots, flip a coin, and roll dice. It stores everyone's money on an SQLite3 database.
A Discord casino bot with a FastAPI web host and interactive demo UI.
It supports:
- Blackjack (reactions for hit/stand/double/split/surrender, insurance, split hands)
- High card (
highcard/war) - Slots (animated GIF reels + credit economy)
- Coin flip and dice roll
- Wallet commands (balance, leaderboard, periodic bonus)
The app starts a web server and, if configured, starts the Discord bot in the same process.
- FastAPI app entrypoint:
app/backend/main.py - Discord bot entrypoint:
app/discord_bot/bot.py - SQLite economy layer:
app/discord_bot/modules/economy.py - Demo UI:
app/backend/static/demo/
Behavior at startup:
- If
DISCORD_TOKENis set, the Discord bot is launched during FastAPI lifespan startup. - If
DISCORD_TOKENis missing, the app runs in web-only mode (demo still works).
- Python 3.10+
- A Discord bot token (only required for Discord mode)
- Create and activate a virtual environment.
- Install dependencies:
pip install -r requirements.txt- Copy env template and edit values:
cp .env.example .env- Run the app:
uvicorn app.backend.main:app --host 0.0.0.0 --port 8000- Open:
http://localhost:8000/http://localhost:8000/demo
Configured in .env (or process environment):
DISCORD_TOKEN: Discord bot token. Leave empty for web-only mode.DISCORD_OWNER_IDS: Comma-separated Discord user IDs for owner-only commands.DISCORD_PREFIX: Prefix command trigger (default:$).DISCORD_DEFAULT_BET: Default money bet (default:100, allowed1..1000000).DISCORD_BONUS_MULTIPLIER: Bonus multiplier foradd(default:5, allowed1..1000).DISCORD_BONUS_COOLDOWN: Bonus cooldown in hours (default:12, allowed1..168).CASINO_DATA_DIR: Base runtime data directory (default:./data).CASINO_DATABASE_PATH(optional): Override SQLite DB path.CASINO_LOG_PATH(optional): Override log file path.
See .env.example for current defaults.
For prefix commands to work correctly, enable these in the Discord Developer Portal:
- Message Content Intent
- Server Members Intent
The bot requests standard intents for guilds, messages, message content, and members.
$ is your DISCORD_PREFIX.
General:
$help [command]$add$money [@member]($creditsalias)$leaderboard($topalias)
Casino:
$blackjack [bet]($bjalias)$highcard [bet]($waralias)$flip <heads|tails> [bet]$roll <1-6> [bet]$slots [bet](credits, bet range 1-3)$buyc <credits>($buy,$baliases)$sellc <credits>($sell,$saliases)
Owner-only:
$set [balance|credits] [user_id] [amount]$kill
The demo frontend is served at / and /demo and talks to these API routes:
GET /api/demo/configPOST /api/demo/commandPOST /api/demo/actionPOST /api/demo/resetGET /api/demo/assets/{asset_id}
The demo runtime intentionally limits commands to:
help,money,blackjack,war,slots
Rate limiting is enabled on demo API endpoints.
Runtime data defaults to ./data:
- Database:
./data/economy.db - Logs:
./data/logs/casino-bot.log
SQLite schema migrations are versioned and applied automatically on startup.
Build:
docker build -t casino-bot .Run (with persistent data mount):
docker run --rm -p 8000:8000 --env-file .env -v "$(pwd)/data:/app/data" casino-botContainer defaults:
- Exposes port
8000 - Runs as non-root user
- Healthcheck targets
GET /api/demo/config

