Discord Bot Troubleshooting
Reference this guide when customers report Discord bot issues. Common symptoms, causes, and resolutions are organized by category.
Connection & Authentication
Section titled “Connection & Authentication”| Symptom | Possible Cause | Resolution |
|---|---|---|
| ”Websocket connecting…” stuck | Invalid token | Regenerate token in Discord Developer Portal, update env var |
| ”Disallowed intents” error | Privileged intents not enabled | Enable MESSAGE_CONTENT, GUILD_MEMBERS intents in Developer Portal |
| Bot exits immediately (code 0) | Missing DISCORD_TOKEN env var | Verify environment variable is set and not empty |
| ”Invalid token” error | Token regenerated elsewhere | Get fresh token from Developer Portal |
| Bot offline in Discord | Container not running | Check portal status, review startup logs |
Token Troubleshooting
Section titled “Token Troubleshooting”- Verify token format (starts with bot user ID encoded in base64)
- Ensure no extra whitespace in environment variable
- Confirm token hasn’t been regenerated since last deployment
- Check token isn’t from wrong bot application
Intent Verification
Section titled “Intent Verification”Required intents depend on bot functionality:
| Feature | Required Intent | Privileged |
|---|---|---|
| Message content | MESSAGE_CONTENT | Yes |
| Member events | GUILD_MEMBERS | Yes |
| Presence updates | GUILD_PRESENCES | Yes |
| Basic commands | GUILDS | No |
| Reactions | GUILD_MESSAGE_REACTIONS | No |
Enable privileged intents at: Discord Developer Portal → Bot → Privileged Gateway Intents
Performance Issues
Section titled “Performance Issues”Memory Problems
Section titled “Memory Problems”Symptoms:
- Bot becomes unresponsive
- “Heap out of memory” errors
- Frequent restarts
Solutions:
- Reduce Discord.js cache sizes
- Implement data pagination
- Clear unused variables
- Upgrade to larger plan
- Use external caching (Redis)
Cache configuration example:
const client = new Client({ intents: [...], makeCache: Options.cacheWithLimits({ MessageManager: 25, GuildMemberManager: 50, PresenceManager: 0 })});CPU Spikes
Section titled “CPU Spikes”Symptoms:
- Slow command responses
- Timeouts
- High resource usage in portal
Solutions:
- Profile code to find bottlenecks
- Offload heavy operations to workers
- Implement request queuing
- Cache expensive computations
- Upgrade plan for more CPU
Slow Commands
Section titled “Slow Commands”Symptoms:
- “Interaction failed” messages
- Commands timing out
- Users reporting lag
Solutions:
- Use
deferReply()for operations > 3 seconds - Cache database queries
- Optimize API calls
- Implement pagination for large responses
Defer example:
await interaction.deferReply();// ... long operation ...await interaction.editReply('Done!');Slash Command Issues
Section titled “Slash Command Issues”| Issue | Cause | Fix |
|---|---|---|
| Commands not appearing | Not registered | Run registration script with correct token |
| Wrong server shows commands | Guild vs global registration | Check registration scope |
| Old commands persist | Cache delay | Wait up to 1 hour for global, restart Discord app |
| ”Unknown interaction” | Handler not implemented | Add interaction handler for command |
Registration Script Example
Section titled “Registration Script Example”const { REST, Routes } = require('discord.js');const rest = new REST().setToken(process.env.DISCORD_TOKEN);
// Global commands (up to 1 hour delay)await rest.put(Routes.applicationCommands(clientId), { body: commands });
// Guild commands (instant, for testing)await rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands });Audio & Voice Issues
Section titled “Audio & Voice Issues”Symptoms:
- No audio playback
- Voice connection drops
- “FFMPEG not found” errors
Solutions:
-
Verify FFmpeg installed:
- Check with support if system package is available
- Some nodes include FFmpeg by default
-
Check permissions:
- Bot needs CONNECT and SPEAK in voice channel
- Verify role hierarchy allows joining
-
Voice adapter setup:
const { joinVoiceChannel } = require('@discordjs/voice');const connection = joinVoiceChannel({channelId: channel.id,guildId: guild.id,adapterCreator: guild.voiceAdapterCreator}); -
Consider Lavalink: For production music bots, external audio servers reduce load
Dependency Issues
Section titled “Dependency Issues”Node.js
Section titled “Node.js”| Error | Cause | Fix |
|---|---|---|
| ”Cannot find module” | Dependencies not installed | Run npm install |
| ”Module not found” | Wrong import path | Check file exists at path |
| node-gyp errors | Native module build failed | Use pre-built binaries or request build tools |
| Version mismatch | Package incompatibility | Check package.json engines, update packages |
Python
Section titled “Python”| Error | Cause | Fix |
|---|---|---|
| ”ModuleNotFoundError” | Package not installed | Run pip install -r requirements.txt |
| ”No module named” | Import path wrong | Check package name vs import name |
| Wheel build failed | Missing system libraries | Request library installation or use pre-built wheels |
Rate Limits
Section titled “Rate Limits”Symptoms:
- 429 errors in logs
- Commands failing intermittently
- “You are being rate limited” messages
Solutions:
- Implement request queuing
- Respect
X-RateLimitheaders - Cache frequently accessed data
- Use bulk operations where possible
- Add exponential backoff
Rate limit handling:
client.rest.on('rateLimited', (info) => { console.log(`Rate limited: ${info.route} for ${info.timeout}ms`);});Database Issues
Section titled “Database Issues”Connection Errors
Section titled “Connection Errors”| Error | Cause | Fix |
|---|---|---|
| ”Connection refused” | Wrong host/port | Verify DATABASE_URL env var |
| ”Access denied” | Wrong credentials | Check username/password |
| ”Too many connections” | Pool exhausted | Implement connection pooling |
| ”Connection timeout” | Network issue | Check if database service is running |
SQLite Corruption
Section titled “SQLite Corruption”Prevention:
- Enable WAL mode
- Schedule graceful restarts
- Regular backups
Recovery:
- Stop the bot
- Restore from backup
- Run integrity check:
PRAGMA integrity_check;
Restart Loops
Section titled “Restart Loops”Symptoms:
- Bot continuously restarting
- “Maximum restart attempts reached”
- Rapid console clear/start cycles
Diagnosis:
- Check console for error message before restart
- Note the exit code:
- Code 0: Clean exit, check if bot completes and exits
- Code 1: Error, check stack trace
- Code 137: Out of memory (OOM killed)
Solutions:
- Fix the underlying error in code
- Increase memory if OOM
- Disable problematic features via env vars
- Rollback to last working backup
Diagnostic Commands
Section titled “Diagnostic Commands”Check Node.js Version
Section titled “Check Node.js Version”node --versionCheck Installed Packages
Section titled “Check Installed Packages”npm listMemory Usage
Section titled “Memory Usage”node -e "console.log(process.memoryUsage())"Python Version
Section titled “Python Version”python --versionPython Packages
Section titled “Python Packages”pip listWhen to Contact Support
Section titled “When to Contact Support”Escalate to hosting support when:
- Suspected infrastructure issues (network, disk, hardware)
- Need system packages installed (FFmpeg, codecs)
- Persistent issues after troubleshooting
- Security concerns
- Billing or account issues
Information to Provide
Section titled “Information to Provide”1. Bot/Server name and ID2. Timeline of when issue started3. Recent changes (code, config, updates)4. Full console output/logs5. Steps already taken to troubleshoot6. Steps to reproduce (if known)