Discord Bot Sharding Explained: When You Need It

How-toBy discordbothostUpdated 2 min read

The short answer: Sharding divides a bot into separate Discord gateway connections, each responsible for some servers. Discord requires it at 2,500 servers and signals missing sharding with close code 4011. Use your library's supported manager, plan memory for every process and respect session-start limits. Sharding helps gateway scale; it does not remove HTTP rate limits.

Key limits (from Discord's docs)

  • At most 2,500 servers per shard. Sharding is mandatory at 2,500+.
  • 1,000 IDENTIFY calls per 24 hours, shared across all shards. Resumes don't count. A crash-looping bot can run out.
  • How many shards can connect at once is set by max_concurrency in the session start limit.
  • The Get Gateway Bot endpoint returns a recommended shard count.

How to shard in each library

  • discord.js: ShardingManager starts one process per shard from your main file (new ShardingManager('./bot.js', { token, totalShards: 'auto' })). Use client.shard.fetchClientValues for totals across shards.
  • discord.py: swap commands.Bot for commands.AutoShardedBot. It runs every shard in one process.
  • JDA: use DefaultShardManagerBuilder.createDefault(token) in place of JDABuilder.

Things that change when you shard

  • Server counts need adding up across shards.
  • Memory and CPU grow with shards, especially with one process per shard in discord.js.
  • Startup is staggered by max_concurrency, so big bots take longer to come fully online.
  • Rate limits don't multiply. The global HTTP limit (50 requests a second) applies to the bot, not per shard.

Do you need it yet?

If your bot is in fewer than about 2,000 servers, you can leave sharding until later, but write code that doesn't assume one shard. Using AutoShardedBot or ShardingManager with 'auto' early costs very little.

Hosting a growing bot on discordbothost

Sharded bots need memory headroom. discordbothost Pro gives 1 GB and a full vCPU for $1.99/month, and Plus gives 2 GB and 1.5 vCPU for $3.49/month, both at a flat price. Watch the live graphs to see when you need the next step. Paid bots also leave through a different outgoing address from free bots, which helps with rate limits.

Sources

https://discord.com/developers/docs/events/gateway (sharding, session start limits); https://discord.com/developers/docs/topics/opcodes-and-status-codes (4011); https://discord.com/developers/docs/topics/rate-limits. Checked .

Questions

When does a Discord bot need sharding?

Discord requires sharding once a bot is in 2,500 or more servers; each shard can handle at most 2,500 servers. Below that, one connection is fine. Without sharding, a large bot is refused with close code 4011 (Sharding required).

How many shards should I use?

Ask Discord: the Get Gateway Bot endpoint returns a recommended shard count. Libraries such as discord.js's ShardingManager, discord.py's AutoShardedClient and JDA's ShardManager use it automatically.

Does sharding need more RAM?

Each shard holds its own connection and its share of the cache, and process-based sharding (like discord.js's ShardingManager) runs one Node process per shard, so memory grows with shard count.

  1. 1https://discord.com/developers/docs/events/gateway
  2. 2https://discord.com/developers/docs/topics/opcodes-and-status-codes
  3. 3https://discord.com/developers/docs/topics/rate-limits
  4. 4https://discordbothost.com/pricing/

Related