![](/img/trans.png)
[英]how to get the users who reacted with an emoji in a message (discord.py)
[英]Check if a list of users reacted to message discord.py rewrite
我正在尝试为机器人发出命令,当消息中提到的每个人都对机器人的响应做出反应时,它会提到原始消息作者
这就是我试过的
if msg.content.startswith('/iniciar'):
async with msg.channel.typing():
mentions = ""
for mention in msg.mentions:
mentions = mentions + " " + mention.mention
bot_msg: discord.Message = await msg.channel.send(mentions + ' confirmem presença reagindo abaixo.')
await bot_msg.add_reaction('✅')
for mention in msg.mentions:
def check(reaction, user):
return user == mention and str(reaction.emoji) == '✅'
try:
reaction, user = await client.wait_for('reaction_add', check=check)
finally:
reactionusers: list = await reaction.users().flatten()
reactionusers.remove(reactionusers[0])
print(reactionusers)
print(msg.mentions)
if reactionusers == msg.mentions:
await msg.channel.send(msg.author.mention)
else:
return
好的,首先,您需要考虑当前实现中的一些事项。 一方面,您可能希望保存您希望机器人在某处观看的消息 ID。 无论是 SQL 还是 Shelve 等等
为此,当调用/iniciar
函数时,将消息 ID 保存在您喜欢的任何首选长期存储方法中,机器人可以检查的某个地方。
然后你需要考虑如何激活这个代码块,我在你当前给定的代码中看不到。 我建议,为了您的目的,使用on_reaction_add
此处有文档: https : on_reaction_add
使用Reaction.message
抓取消息对象,将消息中提到的人的相关信息读取到列表中(类似于你的做法)。
当用户对消息做出反应并on_reaction_add
:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.