Python 如何在不重新启动bot的情况下停止此discord bot命令?
如何在不重新启动bot的情况下停止此discord bot命令Python 如何在不重新启动bot的情况下停止此discord bot命令?,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,如何在不重新启动bot的情况下停止此discord bot命令 @bot.command() async def spam(ctx, *args): response = "" for arg in args: response = response + " " + arg while True: await ctx.channel.send(response) time.sleep(
@bot.command()
async def spam(ctx, *args):
response = ""
for arg in args:
response = response + " " + arg
while True:
await ctx.channel.send(response)
time.sleep(1)
您可以简单地使用一个变量
bot.some\u var=True
而bot.some_var:
等待ctx发送(响应)
如果“满足某些条件”:
循环=错误
如果要在命令中停止循环:
bot.some\u var=True
@bot.command()
异步def垃圾邮件(ctx,*args):
响应=''.join(args)
而bot.some_var:
等待ctx发送(响应)
等待asyncio.sleep(1)
@bot.command()
异步def停止(ctx):
bot.some_var=False
还有两件事:
str.join(list)
代替你做的那种奇怪的for循环asyncio.sleep
而不是time.sleep
,这样代码就不会被阻塞