Python 如何在discord.py上创建自定义函数?
我正在开发一个discord机器人,我必须使用以下功能:Python 如何在discord.py上创建自定义函数?,python,discord.py,Python,Discord.py,我正在开发一个discord机器人,我必须使用以下功能: 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 = a
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 get\u ox(message.author,my\u msg)
请指定它何时返回True。是在添加一个反应后还是在执行函数后立即执行?正如Lu M所说,反应部分是否有效?您如何调用它?我希望message.author对我的_msg作出反应,我得到反应O或X。甚至反应部分也不起作用,我像my_msg=wait message.channel.send()那样调用它;如果没有得到(message.author,my_msg):等待message.channel.send('cancelled');return
@LuM@AhmedKhaled@PatrickHaughYou从未显示过执行此函数的位置,因此没有人能够帮助您解决此问题。请始终包含所有相关代码。