代码
下面是(我的代码的一部分):
@Bot.command()
async def Spy(ctx, user:Member): #I did from discord import * before
author = ctx.message.author
...
@Bot.event
async def on_typing(channel, user, when):
... #... means that there's some irrilevant code between two lines, but it's not a pass
@Bot.event
async def on_message(mess):
if mess.author == author:
if mess.content == "Stop spying!":
global End
End = True
await Bot.process_commands(mess)
global End
if End:
End = False
return #this returns the whole function/command Spy我的代码没有引发错误。
问题
return使Spy命令结束,但事件仍在运行。
问题
您知道如何使所有事件(on_typing和on_message不是唯一的事件)以返回结束吗?
提前感谢!
发布于 2021-08-26 15:50:46
回答
也许我找到了我自己问题的答案:
我必须将on_message作为函数中的第一个事件,然后使用End结束所有其他事件。
编辑
正如@Łukaszński解释的那样,我应该使用Ł方法。
@Bot.command()
async def Spy(ctx, user:Member):
...
while True:
channel, uSer, when = Bot.wait_for("typing") #Instead of on_typing event
if uSer == user:
await ctx.message.author.send(f"{user.mention} is typing in {channel}")
message = Bot.wait_for("message") #Instead of on_message event
if message.content == "Stop":
return比我以前的解决方案更简单更短。
https://stackoverflow.com/questions/68941614
复制相似问题