使用 discord.py-rewrite 制作全局检查功能

Make global check function with discord.py-rewrite

所以,使用 discord.py-rewrite,我知道我可以使用:

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)

检查消息输入(必须来自上下文作者并在上下文通道中)。但是因为我需要检查几个命令,所以我不能只做:

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

然后使用:

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

discord.py 的重写分支不再存在。现在只是v1.

Bot.wait_forcheck 谓词检查要等待的内容,只传递正在等待的事件的参数。这意味着由于您正在等待消息事件,因此只会传递单个消息参数。

完成您想要的事情的一种方法是使用处理 context 参数和 returns 检查谓词的包装方法,例如:

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))