[SOLVED] Can't return the first function from Bot.event on_message



Here’s (a little part) of my code:

async def Spy(ctx, user:Member): #I did from discord import * before
    author = ctx.message.author
    async def on_typing(channel, user, when):
        ... #... means that there's some irrilevant code between two lines, but it's not a pass
    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

There’s no error raised with my code.


return makes the Spy command end, but events keep running.


Do you know how to make all the events (on_typing and on_message aren’t the only ones) end with the return?
Thanks in advance!



Maybe I found the answer to my own question:
I have to put on_message as the first event in the function, and then use End bool to end all the others.


As @Łukasz Kwieciński explained me, I should use the Bot.wait_for() method.

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":

Easier and much shorter than my previous solution.

Answered By – FLAK-ZOSO

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *