A feature-rich Discord bot designed to enhance coding communities with interactive quizzes, leaderboards, and engagement features.
- Automated Questions: Receives coding quiz questions every 20 minutes
- Multiple Choice Format: Simple a/b/c answer format
- Bonus Questions: Random 10% chance for double points
- Real-time Feedback: Instant responses to correct/incorrect answers
- Streak System: Track consecutive correct answers
- Overall Leaderboard (
/codeleaderboard): Top performers by total points - Weekly Leaderboard (
/codeweek): Weekly champions with automatic Monday resets - Streak Leaderboard (
/codestreak): Best current and all-time streaks
- Individual Stats (
/codestats): Personal performance metrics - Visual Flex Cards (
/codeflex): Beautiful profile cards with stats - Rank Tracking: See your position and points to next rank
- Custom gradient text effects
- Hexagonal avatar displays
- Rich Discord embeds
- Professional stat cards
| Command | Description | Usage |
|---|---|---|
/codeleaderboard |
Show top 10 players by total points | /codeleaderboard |
/codeweek |
Display weekly leaderboard (resets Mondays) | /codeweek |
/codestreak |
Show current and best streak leaders | /codestreak |
/codestats |
View your personal statistics | /codestats |
/codeflex |
Generate a visual profile card | /codeflex |
/help |
Get help and command information | /help |
- Join the Quiz: Wait for questions to appear in the designated channel
- Answer Quickly: Type
a,b, orcto answer - Build Streaks: Answer consecutively to build your streak
- Compete Weekly: Participate in weekly competitions
- Check Stats: Use commands to track your progress
- Python 3.8+
- Discord Bot Token
- Discord Server with appropriate permissions
-
Clone the Repository
git clone https://github.com/TheCodeVerseHub/CodeBuddy.git cd CodeBuddy -
Create Virtual Environment
python -m venv .venv source .venv/bin/activate # Linux/Mac # or .venv\Scripts\activate # Windows
-
Install Dependencies
pip install -r requirements.txt
-
Environment Configuration Create a
.envfile in the root directory:DISCORD_BOT_TOKEN=your_bot_token_here QUESTION_CHANNEL_ID=your_channel_id_here
-
Run the Bot
python main.py
| Variable | Description | Required |
|---|---|---|
DISCORD_BOT_TOKEN |
Your Discord bot token from Discord Developer Portal | |
QUESTION_CHANNEL_ID |
Channel ID where quiz questions will be posted |
codebuddyserver/
├── main.py # Bot entry point and configuration
├── database.py # Database operations and management
├── codingquestions.py # Question bank and retrieval
├── requirements.txt # Python dependencies
├── .env # Environment variables (create this)
├── cogs/
│ ├── quiz_cog.py # Quiz functionality and main leaderboard
│ ├── flex_cog.py # Visual profile cards
│ ├── leaderboard_cog.py # Weekly and streak leaderboards
│ └── __pycache__/ # Python cache files
├── assets/
│ └── fonts/ # Custom fonts for visual elements
└── __pycache__/ # Python cache files
- Discord.py 2.6+: Modern Discord API wrapper with slash command support
- SQLite + aiosqlite: Lightweight async database for user data
- Pillow (PIL): Image processing for flex cards
- Python-dotenv: Environment variable management
user_id(INTEGER): Discord user IDcorrect_answers(INTEGER): Total correct answersstreak(INTEGER): Current streakbest_streak(INTEGER): All-time best streaklast_answer_date(TEXT): Date of last activity
user_id(INTEGER): Discord user IDcorrect_answers(INTEGER): Weekly correct answersweek_start(TEXT): Week start date (Monday)
- Automatic Posting: Questions appear every 20 minutes
- Fair Play: Users can only answer once per question
- Bonus System: 10% chance for double points
- Streak Mechanics: Reset on wrong answers, continue on correct ones
- Overall: All-time performance ranking
- Weekly: Current week performance (Monday-Sunday)
- Streak: Current streaks and personal bests
- Gradient Text: Beautiful color transitions
- Hexagonal Avatars: Unique profile picture framing
- Rich Embeds: Professional Discord message formatting
- Progress Indicators: Visual representation of stats
- Send Messages
- Use Slash Commands
- Embed Links
- Read Message History
- Add Reactions
- Question Timer: Modify interval in
quiz_cog.py(@tasks.loop(minutes=20)) - Bonus Chance: Adjust probability in quiz logic
- Visual Themes: Customize colors in flex card generation
- Database: Easily extendable for additional features
- Async Database Operations: Non-blocking database queries
- Cached User Lookups: Efficient Discord user resolution
- Immediate Response Pattern: Prevents Discord interaction timeouts
- Memory Efficient: Minimal resource usage
- Error Handling: Comprehensive exception management
- Auto-reconnection: Automatic restart on connection issues
- Data Validation: Input sanitization and validation
- Graceful Degradation: Continues operation if non-critical features fail
We welcome contributions! Here's how to get started:
- Fork the Repository
- Create Feature Branch:
git checkout -b feature/amazing-feature - Commit Changes:
git commit -m 'Add amazing feature' - Push to Branch:
git push origin feature/amazing-feature - Open Pull Request
- Follow existing code style and patterns
- Add appropriate error handling
- Test features thoroughly before submitting
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
Bot not responding to commands:
- Verify bot permissions in Discord server
- Check if slash commands are synced (
/helpshould appear) - Ensure bot token is correct in
.env
Questions not posting:
- Verify
QUESTION_CHANNEL_IDis correct - Check bot has send message permissions in target channel
- Review console for error messages
Database errors:
- Ensure write permissions in project directory
- Check for corrupted database file
- Restart bot to reinitialize database
Enable debug logging by adding print statements or using Python's logging module for detailed troubleshooting.
- Custom question categories
- Team-based competitions
- Achievement system
- Web dashboard for statistics
- Integration with coding platforms
- Multi-server support
- Advanced analytics
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Contact: Create an issue for support requests
Made with by TheCodeVerseHub
Enhance your coding community with CodeBuddy - where learning meets competition!