Discord error 4011: Sharding required
Last verified against Discord Developer Docs - Opcodes and status codes
The session would have handled too many guilds - you are required to shard your connection in order to connect.What error 4011 means
Your bot is in more guilds than a single gateway connection is allowed to serve, and you identified without sharding (or with too few shards). The documented ceiling is 2,500 guilds per shard; apps in 2,500 or more guilds must shard. Discord closes the connection with 4011 and will not accept an unsharded Identify until the guild count drops or you add shards. It is not reconnectable.
Sharding splits guilds across connections deterministically: a guild lives on shard (guild_id >> 22) % num_shards. You tell Discord your shard layout in the Identify payload's shard array, and each connection then only receives events for its guilds. The GET /gateway/bot endpoint returns a recommended shards value and a session_start_limit with max_concurrency, which governs how many shards may identify per 5 seconds. Libraries implement all of this; you mostly need to turn it on (discord.js ShardingManager or shards: 'auto', discord.py AutoShardedClient).
Hitting 4011 is a milestone: it means the bot grew. But it also means downtime until sharding is enabled, so plan before reaching 2,500.
What it looks like
// WebSocket close frame
code: 4011
reason: "Sharding required"
// GET /gateway/bot
{
"url": "wss://gateway.discord.gg",
"shards": 9,
"session_start_limit": {
"total": 1000,
"remaining": 999,
"reset_after": 14400000,
"max_concurrency": 1
}
}Why it happens
- Bot crossed the 2,500-guild threshold without sharding enabled
- Shard count configured too low after further growth
- Library configured with a fixed shard count that no longer fits
- Large bot moved to a new host with sharding disabled in the new config
How to fix Discord error 4011
- 1Call GET /gateway/bot with the bot token and read shards (recommended count) and session_start_limit.max_concurrency
- 2Enable auto-sharding in your library, or configure at least the recommended number of shards
- 3For multi-process deployments, use a sharding manager and spread shards across processes or machines
- 4Respect max_concurrency when starting shards so identifies are not rate limited
- 5Re-check the recommended shard count periodically as the bot grows
How to stop it recurring
Turn on auto-sharding long before you need it; it costs nothing at small scale. Track guild count as a metric and alert at around 2,000 so capacity planning (and the verification and privileged intent reviews that come with growth) happens on your schedule rather than Discord's.
Sharding thresholds and the identify concurrency that governs multi-shard startup are on the Discord limits page; growth planning for verification and intents, which arrive around the same scale, is covered in Discord bot not responding.
Official reference: Discord Developer Docs - Opcodes and status codes. See all Discord error codes or the Discord limits and quotas.
Related codes
Error 4011 - quick answers
What does Discord error 4011 mean?
Your bot is in more guilds than a single gateway connection is allowed to serve, and you identified without sharding (or with too few shards). The documented ceiling is 2,500 guilds per shard; apps in 2,500 or more guilds must shard. Discord closes the connection with 4011 and will not accept an unsharded Identify until the guild count drops or you add shards. It is not reconnectable.
How do I fix Discord error 4011?
1. Call GET /gateway/bot with the bot token and read shards (recommended count) and session_start_limit.max_concurrency 2. Enable auto-sharding in your library, or configure at least the recommended number of shards 3. For multi-process deployments, use a sharding manager and spread shards across processes or machines 4. Respect max_concurrency when starting shards so identifies are not rate limited 5. Re-check the recommended shard count periodically as the bot grows
Stop debugging Discord by hand
Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.