A Discord bot built with discord.py that enables a counting game in a specified channel. Users count upwards from 1, one number per message. The bot validates the sequence, reacts to correct/incorrect entries, and maintains per-server and global leaderboards.
- Features
- Requirements
- Installation
- Bot Setup
- Usage
- Configuration
- Development
- Troubleshooting
- Contributing
- Support
- π― Counting Game: Users count upwards from 1 in a designated channel
- β Smart Validation: Bot validates correct sequence and prevents consecutive counting by same user
- π¨ Custom Reactions: Support for custom emotes or default β /β reactions with automatic fallback
- βοΈ Admin Commands: Set counting channel and reset count with permission checks
- π Leaderboards: Per-server stats with global rankings
- π Multi-Server Support: Maintains separate counts for each server
- πΎ Local Storage: All data stored in SQLite database with async support
- π Flexible Input: Accepts numbers anywhere in messages (e.g., "5 this is a test")
- π Live Presence: Custom status showing total count across all servers
- π³ Docker Ready: Easy deployment with Docker and Docker Compose
- β° Grace Period System: 5-second countdown when mistakes are made, allowing others to save the count
- π« Same User Protection: Automatically ignores consecutive messages from the same user
- π₯ Auto Reset: Count resets to 0 if no one saves it during grace period
- Python 3.10+
- Discord Bot Token (from Discord Developer Portal)
- Required Bot Permissions:
- Send Messages
- Add Reactions
- Use Slash Commands
- Read Message History
Ready to use immediately! Invite the public bot to your server:
# Clone the repository
git clone https://github.com/jakedev796/counting-bot.git
cd counting-bot
# Set up environment
cp .env.example .env
# Edit .env with your Discord bot token
# Run with Docker (recommended)
docker-compose up -d
# Or run locally
pip install -r requirements.txt
python main.py-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env
Edit
.envand add your Discord bot token:DISCORD_TOKEN=your_discord_bot_token_here DATABASE_PATH=./counting_bot.db -
Run the bot
python main.py
-
Set up environment variables
cp .env.example .env
Edit
.envwith your Discord bot token. -
Create data directory
mkdir data
-
Build and run with Docker Compose
docker-compose up -d
-
Create a Discord Application
- Go to Discord Developer Portal
- Create a new application
- Go to the "Bot" section and create a bot
- Copy the bot token to your
.envfile
-
Invite the Bot to Your Server
- Go to OAuth2 > URL Generator
- Select scopes:
botandapplications.commands - Select permissions:
Send Messages,Add Reactions,Use Slash Commands - Use the generated URL to invite the bot
-
Set Required Intents
- In the Bot section, enable:
- Message Content Intent
- Server Members Intent
- In the Bot section, enable:
-
/setcountingchannel [channel]- Set the counting channel for the server- Requires "Manage Server" permission
- Only one channel per server can be set
-
/resetcount [reason]- Reset the count for the server- Requires "Manage Server" permission
- Clears all user stats for the server
- Optional reason parameter
/leaderboard- View server statistics with global rankings- Shows Current Number, High Score, and Total Score
- Displays global rank for each stat
- Available to all users
- Valid Messages: Only integer messages are processed
- Sequence: Must count in correct order (1, 2, 3, ...)
- User Alternation: No user can count twice in a row (automatically ignored)
- Reactions:
- β for correct counts
- β for incorrect counts or rule violations
- Rapid Counting: Allowed as long as users alternate
- Grace Period: When someone makes a mistake, others have 5 seconds to save the count
- Auto Reset: If no one saves the count in time, it resets to 0
The bot features an exciting 5-second grace period when mistakes are made:
- π¨ Mistake Detection: When someone types the wrong number, a countdown starts
- β° Live Countdown: An embed updates every second showing remaining time
- πͺ Team Save: Other users can type the correct number to save the count
- π« Mistake Maker Lock: The person who made the mistake cannot save it
- π Success: If saved, the count continues with a celebration message
- π₯ Reset: If time runs out, the count resets to 0 and everyone starts over
This creates a thrilling team-based experience where quick thinking and cooperation can save the day!
| Variable | Description | Default |
|---|---|---|
DISCORD_TOKEN |
Your Discord bot token | Required |
DATABASE_PATH |
Path to SQLite database | ./counting_bot.db |
SUCCESS_EMOTE |
Custom emote for correct counts (with fallback) | β
|
ERROR_EMOTE |
Custom emote for incorrect counts (with fallback) | β |
The bot uses SQLite for data storage with the following tables:
- guild_settings: Server configuration and stats
- user_stats: Individual user statistics per server
counting-bot/
βββ bot/
β βββ __init__.py
β βββ main.py # Main bot class
β βββ commands/
β β βββ __init__.py
β β βββ admin.py # Admin slash commands
β β βββ leaderboard.py # Leaderboard command
β βββ cogs/
β β βββ __init__.py
β β βββ counting.py # Counting game logic
β βββ db/
β β βββ __init__.py
β β βββ database.py # Database operations
β βββ utils/
β βββ __init__.py
β βββ helpers.py # Utility functions
βββ main.py # Entry point
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
βββ .env.example # Environment template
βββ README.md # This file
- Commands: Add new slash commands in
bot/commands/ - Cogs: Add new functionality in
bot/cogs/ - Database: Extend
bot/db/database.pyfor new data needs - Utilities: Add helper functions in
bot/utils/helpers.py
-
Bot not responding to commands
- Check if bot has required permissions
- Verify slash commands are synced
- Check bot token is correct
-
Database errors
- Ensure write permissions for database directory
- Check database path in environment variables
-
Counting not working
- Verify counting channel is set with
/setcountingchannel - Check bot has permission to add reactions
- Verify counting channel is set with
The bot logs all activities to console. Check logs for:
- Command usage
- Counting events
- Error messages
- Database operations
Always welcoming contributions! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Found a bug? Please open an issue with:
- Description of the bug
- Steps to reproduce
- Expected vs actual behavior
- Bot logs (if applicable)
Have an idea? I'd love to hear it! Open an issue with your suggestion.
Need help? Here are your options:
- Check the troubleshooting section above
- Review the bot logs for error messages
- Check the Discord.py documentation
- GitHub Issues: Open an issue for bugs or feature requests
Made with β€οΈ by the Jake
If this project helped you, consider giving it a β!