例如,我会输入"! hello ",而bot将继续向回传hello消息,直到我写了类似于"!stop“之类的东西。
发布于 2022-03-25 03:14:22
stop_var = False
@client.command()
async def stop(ctx):
global stop_var
stop_var = True
@client.command()
async def hello(ctx):
global stop_var
stop_var = False
while True:
await ctx.send("Hello")
await asyncio.sleep(1)
if stop_var:
break
很肯定这会起作用的
顺便说一句,如果你这样做的话,你可能会被排除掉,所以也许你的睡眠时间是5秒或更长的空闲时间。
https://stackoverflow.com/questions/71607755
复制相似问题