因此,使用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)发布于 2020-02-02 20:17:30
discord.py的重写分支已不复存在。它现在就是简单的v1。
Bot.wait_for的check谓词用来检查要等待的内容,它只传递被等待的事件的参数,这意味着由于你正在等待一个消息事件,所以它只会被传递一个消息参数。
完成所需操作的一种方法是使用包装器方法,该方法处理context参数并返回检查谓词,例如:
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))https://stackoverflow.com/questions/60024708
复制相似问题