Discord API Rate Limiting: How It Works and How to Handle It in Your Bot
Discord enforces rate limits on API calls. Hit these limits and your requests fail with 429 Too Many Requests. In the worst case, your bot gets temporarily banned from the API. Understanding the rate limit structure prevents these failures.
How Discord Rate Limits Work
Discord applies rate limits at multiple granularities:
Per-route limits: Each API endpoint has its own bucket. Sending 5 messages to channel A doesn't affect your ability to send messages to channel B.
Global limit: 50 requests per second globally across all routes.
Interaction response limit: 3 seconds to respond to a slash command (not a rate limit, but a timeout).
When your bot exceeds a bucket's limit, Discord returns:
{
"message": "You are being rate limited.",
"retry_after": 1.337,
"global": false
}
How discord.js Handles Rate Limits Automatically
discord.js implements automatic rate limiting. It queues requests that would hit a limit and releases them after the retry_after period. For most bots, this is invisible — requests queue briefly and succeed without errors.
You can observe this:
client.rest.on('rateLimited', (rateLimitInfo) => {
console.log(`Rate limited: ${rateLimitInfo.method} ${rateLimitInfo.url}, retry in ${rateLimitInfo.timeToReset}ms`);
});
When Automatic Handling Is Not Enough
Problems arise when:
- Your bot sends bulk messages in loops — Even with queuing, processing is slower than expected:
// BAD: Fires 100 API calls almost simultaneously
for (let i = 0; i < 100; i++) {
await channel.send(`Message ${i}`)
}
// BETTER: Add delays between bulk operations
for (let i = 0; i < 100; i++) {
await channel.send(`Message ${i}`)
await new Promise(resolve => setTimeout(resolve, 100))
}
-
Ban/kick storms — Mass moderation operations. Use rate-limited queues with delay.
-
Webhook spam — Webhooks have their own limits separate from bot limits. 30 messages per minute per webhook.
Global Ban Prevention
If your bot receives more than a specific number of 429 responses in a short period, Discord may issue a temporary global ban (CloudFlare ban). This blocks your VPS IP from the API for minutes to hours.
Prevention:
- Never use raw HTTP clients for Discord — always use a library that respects rate limits
- Add logging on rate limit events
- Implement exponential backoff for any retry logic