0
votes

So, using discord.py-rewrite, I know that I can use:

def check(message):
    """Checks the message author and channel."""
    return message.author == ctx.author and message.channel == ctx.channel
await bot.wait_for("message", timeout=180, check=check)

to check message input (which must be from the context author and in the context channel). But because I need this check for several commands, can't I just make:

def check_msg(context, message):
    return context.author == message.author and context.channel == message.channel

and then use:

await bot.wait_for("message", timeout=180, check=check_msg)
1

1 Answers

2
votes

The rewrite branch of discord.py doesn't exist anymore. It's simply v1 now.

Bot.wait_for's check predicate to check what to wait for only gets passed the parameters of the event being waited for. This means that since you're waiting for a message event, it'll only be passed the single message argument.

One way to accomplish what you want would be to use a wrapper method that handles the context parameter and returns the check predicate, e.g.:

def wrapper(context):
    def check_msg(message):
        return context.author == message.author and context.channel == message.channel
    return check_msg

await bot.wait_for("message", timeout=180, check=wrapper(ctx))