'Check is not defined' 在 client.wait_for 在 discord.py

'Check is not defined' in client.wait_for in discord.py

我想阅读作者在向我的 discord 机器人发出命令 =hi 后发送的消息。所以我用网上找到的这个代码来获取作者发送的内容:

msg = await client.wait_for('message', check=check) #error goes here, 'check' is not defined
await ctx.send(msg.content)

但问题是当此函数为 运行

时未定义 check

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'check' is not defined

我该如何解决? 我没有在这个函数前面定义check,但是如何定义check

检查是这样的:

def check(m):
    return m.author == ctx.author and m.channel == ctx.channel

只需将其添加到您的命令函数及以上

msg = await client.wait_for('message', check=check)

所以:

def check(m):
    return m.author == ctx.author and m.channel == ctx.channel

msg = await client.wait_for('message', check=check)
await ctx.send(msg.content)