python - 如何在 discord.py 上创建自定义函数?
问题描述
我正在开发一个不和谐的机器人,我必须使用以下功能:
async def get_ox(author,my_msg):
ox = ['⭕', '❌']
for i in ox:
await my_msg.add_reaction(i)
def check(reaction, user):
return user == author and str(reaction) in ox
try:
reaction = await client.wait_for('reaction_add', check=check, timeout=10.0)
except asyncio.TimeoutError:
return False
else:
reaction = reaction[0]
if str(reaction)==ox[1]:
return False
else:
return True
但它绝对不起作用,只是返回 True。
我怎样才能做到?
解决方案
我的问题是await
。
我不得不像这样调用函数:await get_ox(message.author, my_msg)
推荐阅读
- python - 使用 PyPDF2 重命名文件时如何解决 PermissionError: [WinError 32]?请继续关注,.close() 不是答案
- matlab - Matab: copy certain rows from text files to another file
- web-applications - Qliksense webapp 是如何工作的?
- powershell - power shell 命令在 Azure Devops 的 Yaml 管道中不起作用
- powershell - 如何将 powershell 变量作为参数扩展到另一个程序?
- powershell - 执行控制台 .NET Core 程序可从终端运行,但不能从脚本运行
- javascript - 如何为 Esri Javascript API 4.18 返回要素图层中点的纬度和经度
- python - python 仅在记录某些内容时才创建日志文件
- django - Django:按日期过滤相关字段会产生不需要的结果
- spring-batch - Spring Batch ORA-08177: 无法为 BATCH_JOB_INSTANCE 序列化此事务的访问