Sending messages in a channel
Making 10 requests to Send Message will take approximately:
// Discord.js - Rate Limit Handling
// Discord.js automatically handles rate limits
// You don't need to manually implement delays
const { REST } = require('@discordjs/rest');
const rest = new REST({ version: '10' }).setToken('YOUR_BOT_TOKEN');
// Example: Send multiple messages with automatic rate limit handling
async function sendMultipleMessages(channel, messages) {
for (const content of messages) {
try {
await channel.send(content);
// Discord.js automatically waits if rate limited
} catch (error) {
if (error.code === 429) {
// Rate limited - Discord.js will retry automatically
console.log('Rate limited, waiting...');
} else {
console.error('Error:', error);
}
}
}
}
// Listen for rate limit events
client.rest.on('rateLimited', (info) => {
console.log(`Rate limited on route ${info.route}`);
console.log(`Retry after: ${info.timeToReset}ms`);
console.log(`Limit: ${info.limit}`);
console.log(`Global: ${info.global}`);
});
// Manual delay for custom logic (1000ms for Send Message)
async function sendWithDelay(channel, messages) {
for (const content of messages) {
await channel.send(content);
await new Promise(resolve => setTimeout(resolve, 1000));
}
}Discord has a global rate limit of 50 requests per second across all endpoints. Libraries handle this automatically.
When rate limited, Discord returns HTTP 429. The response includes a Retry-After header indicating wait time.