A Discord bot that helps track LeetCode questions per server. Users can add, list, and delete questions from a shared list.
- Add Questions:
!addq <question1> <question2> ...
- Add one or more questions to the server's list - List Questions:
!listq
- Display all questions for the current server - Delete Questions:
!delq <id>
- Delete a question by its ID (requires manage messages permission)
-
Clone the repository
git clone <your-repo-url> cd leetcode-bot
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
- Copy
env.example
to.env
- Add your Discord bot token to the
.env
file
cp env.example .env # Edit .env and add your DISCORD_TOKEN
- Copy
-
Run the bot
python leetcode_bot.py
Railway makes deployment super easy with automatic containerization and PostgreSQL database.
- Railway account (free tier available)
- Discord bot token
-
Connect your repository to Railway
- Go to Railway Dashboard
- Click "New Project" → "Deploy from GitHub repo"
- Connect your GitHub repository
-
Add PostgreSQL Database
- In your Railway project, click "New" → "Database" → "PostgreSQL"
- Railway will automatically provide a
DATABASE_URL
environment variable
-
Set Environment Variables
- Go to your project's "Variables" tab
- Add
DISCORD_TOKEN
with your Discord bot token - The
DATABASE_URL
will be automatically set by Railway
-
Deploy
- Railway will automatically detect your Python app
- It will install dependencies from
requirements.txt
- Your bot will be deployed and running!
requirements.txt
: Python dependenciesProcfile
: Tells Railway how to run your app.env.example
: Template for environment variables.gitignore
: Prevents sensitive files from being committed
-
Create a Discord Application
- Go to Discord Developer Portal
- Click "New Application"
- Give it a name (e.g., "LeetCode Bot")
-
Create a Bot
- Go to the "Bot" section
- Click "Add Bot"
- Copy the token (this is your
DISCORD_TOKEN
)
-
Set Bot Permissions
- Go to "OAuth2" → "URL Generator"
- Select scopes:
bot
,applications.commands
- Select permissions:
Send Messages
,Read Message History
,Manage Messages
- Use the generated URL to invite the bot to your server
-
Configure Intents
- In the Bot section, enable "Message Content Intent"
- This is required for the bot to read command messages
Variable | Description | Required | Source |
---|---|---|---|
DISCORD_TOKEN |
Your Discord bot token | Yes | Manual setup |
DATABASE_URL |
PostgreSQL connection string | Yes | Railway auto-provided |
The bot uses SQLite locally and PostgreSQL on Railway:
- Local Development: SQLite (
question_tracker.db
) - Production (Railway): PostgreSQL (automatically provided)
- Railway logs: View in Railway dashboard under your project
- Application logs: Check the console output for INFO/ERROR messages
- Database: Monitor in Railway dashboard under the PostgreSQL service
- Never commit your
.env
file (already in .gitignore) - Use environment variables for sensitive data
- Regularly rotate your Discord bot token
- Monitor bot permissions - only grant necessary permissions
- Railway handles database backups automatically
- Bot not responding: Check if the token is correct and bot is online
- Permission errors: Ensure bot has proper permissions in Discord server
- Database connection errors: Check Railway's PostgreSQL service status
- Deployment failures: Check Railway logs for dependency or environment issues
- Railway logs: Project dashboard → "Deployments" → "View Logs"
- Discord API: Check bot status in Discord Developer Portal
- Database: Railway dashboard → PostgreSQL service → "Connect" tab
- Push changes to GitHub: Railway automatically redeploys
- Monitor Railway dashboard: Check deployment status and logs
- Scale if needed: Railway allows easy scaling in the dashboard
If you prefer traditional server deployment:
- SSH into your server
- Clone the repository
- Install Python dependencies
- Set up environment variables
- Create a systemd service for auto-restart
- Use PostgreSQL or keep SQLite for single instance
If you want containerized deployment elsewhere:
- Create a Dockerfile
- Use docker-compose.yml
- Set environment variables
- Deploy with
docker-compose up -d
For issues or questions:
- Check Railway logs for deployment errors
- Verify your Discord bot setup
- Ensure all environment variables are set correctly
- Check Railway's documentation for platform-specific issues