discord.py how to wait for author message using wait_for?

You need rewrite your check so that it knows who the author is. One way of doing this is to use a closure. Let’s say you have an existing check

def check(message):
    return message.content == "Hello"

You can replace this with a function that generates equivalent check functions with the author you want to check for injected into them

def check(author):
    def inner_check(message):
        return message.author == author and message.content == "Hello"
    return inner_check

Then you would pass the inner check to wait_for by calling the outer check with the appropriate argument:

msg = await client.wait_for('message', check=check(context.author), timeout=30)

For your check this would be

def check(author):
    def inner_check(message): 
        if message.author != author:
            return False
        try: 
            int(message.content) 
            return True 
        except ValueError: 
            return False
    return inner_check

Leave a Comment