我的 discord.py 脚本运行多个实例,但我不知道为什么

发布于 2025-01-18 10:32:04 字数 397 浏览 1 评论 0原文

我在覆盆子上运行Discord.py代码,但有时它再次登录,有人告诉我,这是因为他重新连接。有人还告诉我,您不能有多个实例运行,但在我的日志中是。我的代码每2分钟打印一次列表的长度(额外的时间是请求刮擦站点的时间),但是当他再次登录(单独登录我,没有我做任何事情)时,我的机器人正在运行时,没有重新连接,而是他启动了一个新实例,因为在终端中,时间短于2分钟,这意味着一次多次运行,我该如何解决?同样,一段时间后,机器人只是从不和谐中脱机,并且在代码仍在运行时不再响应消息。

enter image description herei run my discord.py code on my raspberry but sometimes it logs in again, someone from told me that is because he reconnected. Someone also told me you can't have multiple instances running but in my log it is. my code prints the length of a list every 2 minutes (the extra time is the time of requests scraping sites) but when he logs in again(on its own without me doing anything) for a second time whilst my bot is running i think he doesn't reconnect but he starts a new instance because in the terminal the times are shorter than 2 minutes which means there are multiple running at once, how do i fix this? Also after some time the bot just goes offline from discord and doesn't respond to messages anymore while the code is still running.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2025-01-25 10:32:04

不是最好的方法,而是一个:
您可以检查最后一个日志是否超过2分钟,如果没有,则可以终止您的脚本,如果是,请继续工作。因此,只有一个积极的剩余。

Not the best way but one:
You can check if the last log is more than 2 minutes old, if no then terminate your script and if yes let it continue working. So there should be only one active remain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文