如何解决有没有一种方法可以对discord.py wait_for使用异步检查功能?
我想使用异步检查功能:
async def check(reaction,user):
await x
return y
await self.bot.wait_for('reaction_add',check=check)
这会产生一条错误消息,提示您未等待检查功能:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ExtensionFailed: Extension 'cogs.boost' raised an error: SyntaxError: 'await' outside async function
如果我将代码更改为:
async def check(reaction,user):
await x
return y
await self.bot.wait_for('reaction_add',check=await check)
我收到以下错误消息:
TypeError: object function can't be used in 'await' expression
是否可以使用异步检查功能?谢谢!
解决方法
async def predicate(ctx):
# you can use any async code here
result = await stuff()
return result
return commands.check(predicate)
只需从中添加异步即可使用等待功能。
当您调用该函数时,请在前面使用Await
r =等待谓词()
,您可以使用以下代码作为示例来编写异步检查:
{{1}}
更多信息可以在这里找到:discord.py docs
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。