Discord API Rate Limiting: How It Works and How to Handle It in Your Bot

Published on

Rate limit errors crash Discord bots silently. Understanding how Discord's rate limits work prevents outages and keeps your bot responsive.

Written by Alex van der Berg – Infrastructure Engineer at Space-Node – 15+ years combined experience in game server hosting, VPS infrastructure, and 24/7 streaming solutions. Read author bio →

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:

  1. 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))
}
  1. Ban/kick storms — Mass moderation operations. Use rate-limited queues with delay.

  2. 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

Keep your Discord bot running reliably on Space-Node VPS

About the Author

Alex van der Berg – Infrastructure Engineer at Space-Node – Experts in game server hosting, VPS infrastructure, and 24/7 streaming solutions with 15+ years combined experience.

Since 2023
500+ servers hosted
4.8/5 avg rating

Our team specializes in Minecraft, FiveM, Rust, and 24/7 streaming infrastructure, operating enterprise-grade AMD Ryzen 9 hardware in Netherlands datacenters. We maintain GDPR compliance and ISO 27001-aligned security standards.

View Space-Node's full team bio and credentials →

Launch Your VPS Today

Get started with professional VPS hosting powered by enterprise hardware. Instant deployment and 24/7 support included.

Discord API Rate Limiting: How It Works and How to Handle It in Your Bot