PluginsDiscord
Discord Error Handlers
Built-in and custom error handling for Discord
The Discord plugin includes built-in error handlers for common Discord API error scenarios.
New to Corsair? Learn about error handling before customizing error handlers.
Full Implementation: See the Discord plugin source code.
Built-in Error Handlers
Rate Limit Errors
Triggers: HTTP 429 status or error messages containing rate limit
Behavior:
- Maximum retries: 5
- Respects
Retry-Afterheader
Example:
// Corsair handles rate limits automatically
await corsair.discord.api.messages.send({
channelId: "1234567890",
content: "This will retry if rate limited",
});Authentication Errors
Triggers: HTTP 401 status or errors containing invalid token, unauthorized
Behavior:
- Maximum retries: 0 (no retries)
- Fails immediately for manual intervention
How to Fix:
- Verify your bot token is valid
- Check the token hasn't been regenerated in the Discord Developer Portal
- Ensure the bot is still a member of the target guild
Permission Errors
Triggers: HTTP 403 status or errors containing missing permissions, forbidden
Behavior:
- Maximum retries: 0 (no retries)
- Fails immediately
How to Fix:
- Check the bot has the required permissions in the server
- Verify the bot role is above the roles it's trying to manage
- Ensure the bot has access to the channel
Not Found Errors
Triggers: HTTP 404 status
Behavior:
- Maximum retries: 0 (no retries)
- Fails immediately
Network Errors
Triggers: Connection errors, timeouts
Behavior:
- Maximum retries: 3
- Uses exponential backoff
Custom Error Handlers
discord({
errorHandlers: {
SLOW_MODE_COOLDOWN: {
match: (error) => {
return error.message.includes("slowmode");
},
handler: async (error, context) => {
return {
maxRetries: 3,
headersRetryAfterMs: 5000,
};
},
},
},
})For comprehensive error handling strategies, patterns, and best practices, see the Error Handling concepts page.