【发布时间】:2022-01-04 02:03:41
【问题描述】:
如果机器人从频道收到“!停止”命令,如何停止脚本的执行? 我只是在学习创建这样的机器人,所以我当前的代码是:
bot = commands.Bot(command_prefix='!')
@bot.command(name='stop')
async def here(ctx):
while True:
print(2)
time.sleep(15)
bot.run(TOKEN)
所以我有 3 个 selenium 驱动程序在不同的机器上工作,我想通过不和谐通道建立通信(每台机器都有自己的机器人)。目前,首先打开特定 URL 的机器将向频道发送停止消息并关闭与聊天的连接,而其他两台机器应在消息后立即停止。
所以,想法
page_opened = True
while page_opened = True:
do something and listen
if there is a message stop:
page_opened = false
我应该如何处理不和谐机器人的这个想法?有什么提示吗?
【问题讨论】:
-
stackoverflow.com/questions/64473974/… 说你应该返回一些东西(虽然我不确定它是否是一个函数)。您总是可以尝试:
while running:并在开始之前将 running 设置为 true,但一旦调用!stop就设置为 false。 -
@LarrytheLlama 感谢您的评论。但我也没有完全理解所提供的解决方案......
标签: python discord discord.py