简体   繁体   English

AutoShardedBot 如何在 discord.py 中工作?

[英]How does AutoShardedBot work in discord.py?

Would someone explain how sharding works, specifically discord.ext.commands.AutoShardedBot ?有人会解释分片是如何工作的,特别是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. If by "multiple servers" you mean physical machines, no, it's a single python instance.如果“多台服务器”是指物理机,不,它是单个 python 实例。
  2. Discord requires sharding past 2.5k guilds. Discord 需要分片超过 2.5k 个公会。
  3. Guilds are assigned to shard by (guild_id >> 22) % shard_count公会通过(guild_id >> 22) % shard_count分配给分(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.如果你需要把它拆分到多台机器上,你可以将shard_idshard_count传递给一个普通的Bot实例。

Discord Docs on Sharding Discord 关于分片的文档

Would someone explain how sharding works, specifically discord.ext.commands.AutoShardedBot ?有人会解释分片的工作原理,特别是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.谢谢你的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM