不和谐的机器人如何处理来自多个服务器的事件 [英] How does a discord bot handle events from multiple servers
问题描述
我正在使用discord.py(重写分支)为我的服务器开发一个discord机器人,我需要邀请该机器人到多台服务器并同时使用。
I'm developing a discord bot using discord.py (rewrite branch) for my servers and I need to invite the bot to multiple servers and use it simultaneously.
我的问题是:
我是否需要为每台服务器设置新线程还是机器人?将事件排队并一一处理?如果确实将它们排在队列中,我应该使用它还是使用单独的线程?
Do I need to set up a new thread for every server or does the bot queue events and handle them one by one? if it does queue them, should I just use that or use separate threads?
抱歉,如果这不是一个笨拙的问题,但是我对discord.py还是很陌生
Sorry if this is a noobish question but I'm fairly new to discord.py and I don't really understand how it works just yet.
感谢阅读
推荐答案
否,您只需要定义回调(主要使用 Client.event
和 Bot.command
),则机器人会在发生某些情况时执行。侦听服务器上发生的事件的所有逻辑都已为您解决。 有关一些示例,请参见discord.py项目中的examples目录。
No, you just need to define the callbacks (mainly using Client.event
and Bot.command
) that the bot will execute when something happens. All of the logic for listening for events happening on the servers has been taken care of for you. See the examples directory in the discord.py project for some examples.
如果您的机器人被广泛使用(数百台服务器),则必须开始使用分片,这是在同一实例的多个实例之间自动拆分流量的过程机器人。您可以查看 AutoShardedClient
以查看其工作原理。
If your bot is used very widely (hundreds of servers) you will have to start using sharding, which is a process of automatically splitting the traffic between multiple instances of the same bot. You can look at the documentation for the AutoShardedClient
to see how that would work.
这篇关于不和谐的机器人如何处理来自多个服务器的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!