为什么我的Raspberry Pi 4重新启动我的脚本,然后将其关闭?

发布于 2025-01-18 05:50:43 字数 556 浏览 0 评论 0原文

我在 Raspberry Pi 4 上运行 Discord py 脚本,但过了一会儿(大约 45 分钟),当我什么都没做时,它就会重新启动。一段时间后它就会关闭而不会出现错误。为什么会出现这种情况?当我在 heroku.com 上使用它时,我的脚本工作得很好,但现在我的锉刀在我不想要的情况下重新启动(我知道它重新启动,因为它打印了我的 on_ready() 消息)。我该如何解决这个问题?我尝试在 Raspberry 上的编辑器中运行它,但也会重新启动。一段时间后它也会关闭,然后我的机器人不再响应。以下是我的 on_ready 代码:

@bot.event
async def on_ready():
  print(f'Logged in as {bot.user}'.format(bot))

更新: 我认为它不会重新启动它,但它会再次运行它,因为通常我会发送 1 个嵌入,但现在就像同一件事

更新 2 一样一次嵌入 8 个或 7 个: 这可能是一个连接错误,discord.py discord 中的某人告诉我我应该在我的代码中处理它。我怎样才能做到这一点?

I run a Discord py script on my Raspberry Pi 4, but after a while (around 45 minutes) it just restarts when I haven't done anything. After some time it just turns off without an error. Why does this happen? My script worked fine when I used it on heroku.com but now my rasp restarts without me wanting it (I know it restarts because it prints my on_ready() message). How can I solve this? I tried running it in the editor on the Raspberry but that also restarts. After some time it also turns off and then my bot doesn't respond anymore. Below is my piece of code for on_ready:

@bot.event
async def on_ready():
  print(f'Logged in as {bot.user}'.format(bot))

Update:
I think it doesn’t restart it but it runs it again because normally I get 1 embed sent but now like 8 or 7 at once of the same thing

Update 2:
It probably is a connection error, someone in the discord.py discord told me i should handle it in my code. How can i do that?

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

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

发布评论

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

评论(1

从此见与不见 2025-01-25 05:50:43

答案不是我的代码中的内容,Discord.py 重新连接,它们继续我在断开连接之前运行的循环函数,但我不知道这一点,所以我在他重新连接后再次调用该命令,这导致该函数运行多个有时不是整个机器人,所以这就是他向嵌入内容发送垃圾邮件的原因。解决方案是忽略重新连接,因为一切都会在断开连接的地方继续! :)

The answer wasn't something in my code, Discord.py reconnects and they continue my loop function that was running before the disconnect but i didn't know that so i called the command again after he reconneted, which resulted in the FUNCTION running multiple times not the whole bot, so that was the reason he spammed the embeds. The solution, just ignore the reconnect because everything continues where it disconneted! :)

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