A modern Discord bot that automatically fetches and shares LeetCode daily challenges
- ๐ Automatic Daily Challenge: Automatically retrieves and posts LeetCode daily challenges
- โฐ Scheduled Delivery: Configurable posting time for each server
- ๐ฎ Slash Commands: Easy-to-use slash commands for manual control
- ๐ Rich Information: Includes title, difficulty, link, tags, and more
- ๐ Multi-server Support: Independent settings for each Discord server
- ๐ Custom Notifications: Configurable role mentions and channels
- ๐ Timezone Support: Server-specific timezone settings
- ๐ Historical Challenges: View past daily challenges by date
- ๐ Problem Lookup: Query single or multiple LeetCode problems with custom titles and messages
- ๐ Submission Tracking: View recent accepted submissions for any user
- ๐ค AI-Powered Features: Optional problem translation and inspiration (requires Gemini API key)
- ๐พ Smart Caching: Efficient caching system for better performance
-
Clone the repository:
git clone https://github.com/cxyfer/leetcode-daily-discord-bot.git cd leetcode-daily-discord-bot
-
Configure your bot:
# Copy and edit the configuration file cp config.toml.example config.toml # Edit config.toml with your settings # Alternative: Use environment variables (.env) cp .env.example .env # Edit .env with your Discord bot token
-
Run database migration (if upgrading from older version):
# Migrate server settings from settings.db to data.db sqlite3 data/data.db < data/migrate_settings.sql
-
Run the bot:
uv run bot.py
The bot supports two configuration methods:
Create a config.toml
file from the example:
[discord]
token = "your_discord_bot_token_here"
[llm.gemini]
api_key = "your_google_gemini_api_key_here" # Optional, for AI features
[schedule]
post_time = "00:00" # Default posting time
timezone = "UTC" # Default timezone
See config.toml.example
for all available options.
For backward compatibility, you can use a .env
file:
DISCORD_TOKEN=your_bot_token_here
GOOGLE_GEMINI_API_KEY=your_gemini_api_key_here # Optional
POST_TIME=00:00 # Optional
TIMEZONE=UTC # Optional
Note: Environment variables take precedence over config.toml
settings.
Send Messages
Embed Links
Use Slash Commands
Message Content
- Receive message content- Note: When the bot joins more than 100 servers, this permission needs to be verified and approved by Discord
Command | Description | Required Permissions |
---|---|---|
/daily [date] [public] |
Display LeetCode.com (LCUS) daily challenge โข Optional: YYYY-MM-DD for historical challenges โข Optional: public - Show response publicly (default: private)โข Note: Historical data available from April 2020 onwards |
None |
/daily_cn [date] [public] |
Display LeetCode.cn (LCCN) daily challenge โข Optional: YYYY-MM-DD for historical challenges โข Optional: public - Show response publicly (default: private) |
None |
/problem <problem_ids> [domain] [public] [message] [title] |
Query one or multiple LeetCode problems โข problem_ids : Single ID (e.g., 1) or comma-separated IDs (e.g., 1,2,3)โข domain : com or cn (default: com)โข public : Show response publicly (default: private)โข message : Optional personal message/note (max 500 chars)โข title : Custom title for multi-problem mode (max 100 chars)โข Note: Supports up to 10 problems per query |
None |
/recent <username> [limit] [public] |
View recent accepted submissions for a user โข username : LeetCode username (LCUS only)โข limit : Number of submissions (1-50, default: 20)โข public : Show response publicly (default: private) |
None |
/set_channel |
Set notification channel for daily challenges | Manage Channels |
/set_role |
Set role to mention with daily challenges | Manage Roles |
/set_post_time |
Set posting time (HH:MM format) | Manage Guild |
/set_timezone |
Set server timezone for scheduling | Manage Guild |
/show_settings |
Display current server settings | None |
/remove_channel |
Remove channel settings | Manage Channels |
/daily # Get today's LeetCode.com challenge (private)
/daily public:true # Get today's challenge and show response publicly
/daily date:2024-01-15 # Get historical challenge from Jan 15, 2024
# Single problem lookup
/problem problem_ids:1 # Get Two Sum problem from LeetCode.com (private)
/problem problem_ids:1 public:true # Get Two Sum problem publicly
# Multiple problems lookup
/problem problem_ids:1,2,3 # Get multiple problems with overview
/problem problem_ids:1,2,3 title:Dynamic Programming Practice # Custom title
/problem problem_ids:1,2,3 message:Today's study plan # With personal note
/problem problem_ids:1,2,3 title:Weekly Contest Problems message:Need to practice these # Both title and message
# Multi-problem with domain selection
/problem problem_ids:1,2,3 domain:cn # Query from LeetCode.cn
/recent username:alice # View 20 recent submissions (private)
/recent username:alice limit:50 # View 50 recent submissions
/recent username:alice limit:50 public:true # View 50 submissions publicly
/set_channel # Set current channel for daily notifications
/set_role # Configure role to ping
/set_post_time time:08:00 # Set daily post time to 8:00 AM
/set_timezone timezone:America/New_York # Set timezone
/show_settings # View current configuration
- Set up notification channel using
/set_channel
(Required) - Configure role mentions with
/set_role
(Optional) - Set posting time and timezone (Optional)
- Verify settings with
/show_settings
The /problem
command supports querying multiple problems at once with enhanced customization:
When querying multiple problems, the bot displays:
- Grouped Display: Problems organized in groups of 5 per field
- Problem Links: Direct clickable links to LeetCode problems
- Difficulty Indicators: Color-coded emojis (๐ข Easy, ๐ก Medium, ๐ด Hard)
- Problem Stats: Rating and acceptance rate when available
- Interactive Buttons: Click numbered buttons to view detailed problem information
- Custom Title: Replace the default title with your own (max 100 characters)
- Personal Message: Add notes, study plans, or context (max 500 characters)
- User Attribution: Shows your name and avatar when title or message is provided
# Study plan organization
/problem problem_ids:70,322,518 title:๐ Dynamic Programming Week 1 message:Focus on bottom-up approach
# Contest preparation
/problem problem_ids:1,15,42 title:๐ Weekly Contest #420 Prep message:Practice these before Sunday
# Topic-based practice
/problem problem_ids:104,226,543 title:๐ณ Binary Tree Fundamentals message:Master tree traversal first
- ๐ฎ Enhanced Command Interface
- Add slash command prompts
- Reply in the same channel where slash commands are used
- Add
/problem
command for querying problems by ID - Enhanced
/problem
command with multi-problem support and customization - Add
/recent
command for viewing user submissions - Support historical daily challenges with date parameter
- โ๏ธ Advanced Configuration System
- Allow admin users to set the configuration
- Set the channel to post the daily challenge
- Set the posting time and timezone
- Set the role to mention
- Set customizable message templates
- Integrate the existing excessive setup instructions
- More flexible notification settings
- Allow admin users to set the configuration
- ๐ Multi-server Infrastructure
- Support server-specific configurations
- ๐ Code Optimization
- Implement improved runtime logging
- Implement modular architecture
- Add comprehensive documentation
- ๐จ๐ณ LeetCode.cn Integration
- Add slash command
/daily_cn
for LeetCode.cn daily challenge - Implement separate scheduler for LeetCode.cn challenges
- Add slash command
- ๐๏ธ Database Integration
- Store and query problem information in database
- Enable historical daily challenge lookup
- ๐ Large Language Model Integration
- Integrate LLM to generate problem translation and inspiration
- Cache LLM results to improve performance
- ๐ User Engagement Features
- Track submission records of specific users
- Interactive navigation for viewing multiple submissions
- Paginated display with clean UI
- Allow users to configure tracked LeetCode accounts
- Implement server-wide submission leaderboards
- ๐ณ Containerization Support
- Add Docker compose file and image
- ๐ Internationalization
- Support multiple display languages
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- discord.py - Discord bot framework
- tomli - TOML parsing for Python < 3.11
- python-dotenv - Environment variable management
- requests - HTTP library for API calls
- pytz - Timezone handling
- beautifulsoup4 - HTML parsing
- colorlog - Colored logging output
- langchain - LLM application framework
- langchain-google-genai - Google Gemini LLM integration
- aiohttp - Asynchronous HTTP client/server
This project is licensed under the MIT License - see the LICENSE file for details.