How does AutoShardedBot work in discord.py?

Viewed 2798

Would someone explain how sharding works, specifically discord.ext.commands.AutoShardedBot? I put multiple questions below:

  • Does it run on multiple servers?
  • If not, how is it beneficial to shard it?
  • Do guilds sometimes switch between shards?
  • How do I use one database if the bot runs on multiple servers?

Thanks for your time.

1 Answers
  1. If by "multiple servers" you mean physical machines, no, it's a single python instance.
  2. Discord requires sharding past 2.5k guilds.
  3. Guilds are assigned to shard by (guild_id >> 22) % shard_count
  4. Make the database accessible over the network, be sure to secure it with a strong password, connect to it from each.

if you need to split it to multiple machines, you can pass shard_id and shard_count to a normal Bot instance.

Discord Docs on Sharding

Related