我正在执行一个命令,您需要使用表情符号确认某些内容。
我有一个 wait_for("reaction_add")
,带有一个 lambda 函数的支票。
我的以下代码是:
try:
reaction, user = await self.client.wait_for("reaction_add",
check=lambda react, usr: str(reaction.emoji) == "✅" and usr.id == ctx.author.id, timeout=60)
print(reaction.emoji)
except asyncio.TimeoutError:
await confirm_msg.edit(content="This message has timed out!", embed=None)
但它不会打印出反应表情符号。 没有检查代码工作正常,所以它与检查有关。我该如何解决?
谢谢!
答案 0 :(得分:2)
Col1 Col2 Col3 Combos
0 A A A A
1 NaN B B B
2 B B C B_C
3 B A A A_B
4 C C C C
答案 1 :(得分:1)
lambda 函数本质上与普通函数相同。
您的 lambda:
lambda react, usr: str(reaction.emoji) == "✅" and usr.id == ctx.author.id
将等于定义以下函数:
# Here we are within the wait_for(reaction_add)
def f(react, usr):
return str(reaction.emoji) == "✅" and user.id == ctx.author.id
# Rest of the code
问题是 reaction_add
没有定义 react
或 usr
。解决您的代码的方法是这样的:
reaction, user = await self.client.wait_for("reaction_add", check=lambda reaction,
user: str(reaction.emoji) == "✅" and user.id == ctx.author.id, timeout=60)
答案 2 :(得分:0)
你可以试试这个,不用 lambda 函数:
@client.event
async def on_raw_reaction_add(payload):
reaction = str(payload.emoji)
if reaction == "✅" and usr.id == ctx.author.id:
print('do something')
else:
print('something else')