我正在为我的服务器使用 discord.py(重写分支)开发一个不和谐机器人,我需要将机器人邀请到多个服务器并同时使用它.
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 项目中的示例目录以获取一些示例.
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.
这篇关于Discord 机器人如何处理来自多个服务器的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!