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 any LeetCode problem by ID
- ๐ 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 <id> [domain] [public] |
Query any LeetCode problem by ID โข id : Problem number (1-4000)โข domain : com or cn (default: com)โข public : Show response publicly (default: private) |
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
/problem problem_id:1 # Get Two Sum problem from LeetCode.com (private)
/problem problem_id:1 public:true # Get Two Sum problem publicly
/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
- ๐ฎ 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 - 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.