【问题标题】:How can i use the wait_for("reaction_add") function only for a specific message? discord.py如何仅将 wait_for("reaction_add") 函数用于特定消息?不和谐.py
【发布时间】:2021-06-20 21:57:00
【问题描述】:
就像机器人不会读取消息的任何其他反应,而只会读取特定消息。
在此代码中添加reaction.message == msgg 会有助于解决问题吗?
(我不知道该功能是否存在,我也测试过,但对我不起作用)
reaction, user = await client.wait_for("reaction_add")
if user == members.user and str(reaction.emoji) == "✔️":
await members.user.send("your answer is ✔️")
else:
return
【问题讨论】:
标签:
python
async-await
discord.py
【解决方案1】:
这适用于wait_for 函数的check 参数:
reaction, user = await client.wait_for("reaction_add", check=lambda m: m.id == MESSAGE_ID)
if user == members.user and str(reaction.emoji) == "✔️":
await members.user.send("your answer is ✔️")
else:
return
(如果 lambda m 和 m.id 适用于反应,您必须对此进行测试)
【解决方案2】:
您可以为此使用on_reaction_add 函数,然后检查用户正在响应的消息是否是所需的消息。
@client.event
async def on_reaction_add(reaction, user):
if user.bot:
return
my_message_id = 1234567
if reaction.message.id == my_message_id
await message.channel.send("Your answer is ✔️")
else:
return
【解决方案3】:
您将检查reaction.message.content 是否与您想要的消息相同。
reaction, user = await client.wait_for("reaction_add")
if reaction.message.content == "<desired message>":
if user == members.user and str(reaction.emoji) == "✔️":
await members.user.send("your answer is ✔️")
else:
return