A comprehensive Discord bot for managing XP, levels, and leaderboards with image generation capabilities.
Features โข Installation โข Configuration โข Commands โข API โข Contributing
- ๐ฏ XP System: Track user XP from messages and voice activity
- ๐ Level System: Automatic level calculation with custom formulas (exponential or XP-anchors)
- ๐๏ธ Role Rewards: Automatic role assignment based on levels
- ๐ Leaderboards: Beautiful image-based leaderboards (permanent & weekly)
- โ๏ธ Admin Commands: Full control over XP, levels, and settings
- ๐ Web Service: REST API for external integrations
- ๐ค Voice Tracking: Real-time voice activity monitoring
- ๐ฌ Message Tracking: Smart message XP with cooldowns
- ๐ Security: Environment-based configuration with sensitive data protection
- Python 3.8 or higher
- Discord Bot Token (Get one here)
- Discord Server (Guild) with appropriate permissions
-
Clone the repository
git clone https://github.com/NourEldeenMahmoud/XPBot.git cd XPBot -
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp config/env.example .env # Edit .env with your actual values -
Set up configuration file
cp config/config.example.json config.json # Edit config.json with your server settings -
Configure your bot
- Go to Discord Developer Portal
- Create a new application
- Go to "Bot" section and copy the token
- Enable required intents (Message Content, Server Members, Voice States)
- Add the bot to your server with appropriate permissions
-
Run the bot
python main.py
Or:
python -m src.bot
Create a .env file with the following variables:
# Required
DISCORD_TOKEN=your_discord_bot_token_here
GUILD_ID=your_guild_id_here
# Optional
ANNOUNCEMENTS_CHANNEL_ID=your_announcements_channel_id_here
MOD_LOG_CHANNEL_ID=your_mod_log_channel_id_here
WEBHOOK_URL=your_webhook_url_here
DATABASE_PATH=xp_bot.db
LOG_LEVEL=INFOThe config.json file contains all bot settings:
- XP Settings: Message and voice XP ranges, cooldowns
- Channel Whitelists: Which channels track XP
- Role Rewards: Automatic role assignment at specific levels
- Level Formula: Customizable level calculation (exponential or XP-anchors)
- Exempt Roles: Roles that don't earn XP
See config.example.json for a template.
The bot needs the following permissions:
- โ Send Messages
- โ Embed Links
- โ Attach Files
- โ Manage Messages (for delete command)
- โ Manage Roles (for role rewards)
- โ View Channels
- โ Connect (for voice tracking)
- โ Speak (for voice tracking)
Required Intents:
- Message Content Intent
- Server Members Intent
- Voice States Intent
| Command | Description |
|---|---|
!rank |
Show your current rank, XP, and level |
!leaderboard |
Show permanent leaderboard (top 10) |
!weeklyleaderboard |
Show weekly activity leaderboard (top 10) |
| Command | Description | Permission |
|---|---|---|
!setxp @user <amount> |
Set user's permanent XP | Administrator |
!setweekly @user <amount> |
Set user's weekly XP | Administrator |
!setlevel @user <level> |
Set user's level | Administrator |
!resetxp @user |
Reset all user data | Administrator |
!resetweekly |
Reset weekly leaderboard | Administrator |
!delete <amount> |
Delete last N messages | Manage Messages |
!config |
Show current configuration | Administrator |
The bot includes a FastAPI web service for external integrations:
http://localhost:8000
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Health check |
GET |
/leaderboard?limit=10 |
Get permanent leaderboard |
GET |
/weeklyboard?limit=10 |
Get weekly leaderboard |
GET |
/user/{user_id} |
Get user statistics |
GET |
/stats |
Get overall bot statistics |
GET |
/config |
Get current bot configuration (read-only) |
{
"leaderboard": [
{
"rank": 1,
"user_id": 123456789,
"permanent_xp": 50000,
"level": 25
}
],
"total_entries": 10,
"guild_id": 987654321
}XPBot/
โโโ main.py # Main entry point
โโโ src/ # Source code
โ โโโ bot.py # Main bot entry point
โ โโโ config_manager.py # Configuration management
โ โโโ database.py # Database operations
โ โโโ xp_manager.py # XP and level calculations
โ โโโ web_service.py # FastAPI web service
โ โโโ cogs/ # Bot command modules
โ โโโ xp_commands.py # XP-related commands
โ โโโ message_tracker.py # Message XP tracking
โ โโโ voice_tracker.py # Voice XP tracking
โ โโโ assistant.py # Assistant features
โโโ config/ # Configuration files
โ โโโ config.example.json # Configuration template
โ โโโ env.example # Environment variables template
โโโ tests/ # Test files
โ โโโ test_bot.py # Bot tests
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
-
Never commit sensitive files
.env- Contains your bot tokenconfig.json- Contains server-specific IDs*.db- Database files
-
Keep your bot token secret
- Anyone with the token can control your bot
- Rotate tokens periodically
- Use environment variables for all sensitive data
-
Production Deployment
- Use environment variables for all configuration
- Set up proper logging and monitoring
- Use a production database (PostgreSQL recommended)
- Enable rate limiting on web service
- Set up health checks
- Connect your GitHub repository to Render
- Create a new Web Service
- Set environment variables in Render dashboard
- Set build command:
pip install -r requirements.txt - Set start command:
python bot.py - Deploy!
- Create a Heroku app
- Set environment variables using
heroku config:set - Deploy using Git:
git push heroku main
- Clone the repository
- Set up environment variables
- Use systemd or PM2 for process management
- Set up reverse proxy (nginx) for web service
Docker support is planned for future releases.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please read CONTRIBUTING.md for details on our code of conduct.
This project is licensed under the MIT License - see the LICENSE file for details.
- discord.py - Discord API wrapper
- FastAPI - Modern web framework
- Discord community for feedback and suggestions
- ๐ Report a Bug
- ๐ก Request a Feature
- โ Ask a Question
Made with โค๏ธ for the Discord community
โญ Star this repo if you find it helpful!