![](/img/trans.png)
[英]Is there a way to use an async check function for discord.py wait_for?
[英]Is there a way to use an async check function for discord.py wait_for()?
我想使用異步檢查 function:
async def check(reaction, user):
await x
return y
await self.bot.wait_for('reaction_add', check=check)
這會產生一條錯誤消息,指出不等待檢查 function:
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
有什么方法可以進行異步檢查 function? 謝謝!
async def predicate(ctx):
# you can use any async code here
result = await stuff()
return result
return commands.check(predicate)
只需添加 async in from 即可使用 await 功能..
此外,當您調用 function 時,請在前面使用 Await
r = 等待謂詞()
您可以使用以下代碼作為示例來編寫異步檢查:
def mycheck():
async def predicate(ctx):
# you can use any async code here
result = await stuff()
return result
return commands.check(predicate)
更多信息可以在這里找到: discord.py 文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.