我该如何在运行且尚未完成时呼叫停止循环?

发布于 2025-01-30 03:58:38 字数 109 浏览 5 评论 0原文

使用不和谐本身的文本触发CTRL+C?

即使尚未完成,我如何将Close()与Discord的文本一起停止WALE循环?

如何使用Discord的文本停止客户端(token)?

Triggering Ctrl+C with a text from Discord itself?

How can I use close() with a text from Discord to stop the while loop even if it is not finished yet?

How can I stop client.run(TOKEN) with a text from Discord?

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

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

发布评论

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

评论(1

再见回来 2025-02-06 03:58:38

您可以使用Sigint信号,这是Control-C时的信号。请参阅在这里有关更多信息。然后,您可以将机器人发送到本身:

import os
import signal

def do_control_c_interrupt():
    os.kill(os.getpid(), signal.SIGINT)

然后,如果您需要停止机器人,则可以do_control_c_interrupt()内部。

You can use the SIGINT signal, which is the signal when you Control-C. See here for more information. You can then get the bot to send the signal to itself:

import os
import signal

def do_control_c_interrupt():
    os.kill(os.getpid(), signal.SIGINT)

Then, you can do_control_c_interrupt() inside of a command if you need to stop the bot.

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