[英]How can i use the wait_for(“reaction_add”) function only for a specific message? discord.py
Like the bot won't read any other reactions of messages but only of a specific message.就像机器人不会读取消息的任何其他反应,而只会读取特定消息。
will adding reaction.message == msgg
into this code helps the trick?将
reaction.message == msgg
添加到此代码中会有所帮助吗? (I don't know whether that function even exists and I did test that too but doesn't work for me) (我不知道 function 是否存在,我也测试过,但对我不起作用)
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
You would check if the reaction.message.content
is the same as the message you desire.您将检查
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
You can use the on_reaction_add
function for this, and then check if the message the user is reacting to is the desired one.您可以为此使用
on_reaction_add
function,然后检查用户反应的消息是否是所需的消息。
@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
This works fine with the check
parameter of the wait_for
Function:这适用于
wait_for
Function 的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
(Idk if the lambda m
and m.id
works for reactions, you would have to test this out) (如果
lambda m
和m.id
适用于反应,您将不得不对此进行测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.