检查用户列表是否对消息 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,搁置,随便什么

为此,当 /iniciar 函数被调用时,将消息 ID 保存在您喜欢的任何首选长期存储方法中,机器人可以检查的地方。

然后你要考虑如何激活这个代码块,我在你当前给定的代码中看不到它。我建议,出于您的目的,使用 on_reaction_add 此处有文档:https://discordpy.readthedocs.io/en/latest/api.html#discord.on_reaction_add

使用Reaction.message抓取消息对象,将消息中提到的人的相关信息读取到列表中(与您的做法类似)。

当用户对消息做出反应并调用 on_reaction_add 时:

  1. 检查正在响应的消息是否在您的存储解决方案中,如果是消息,您正在等待看到对继续的响应
  2. 然后检查做出反应的用户是否在该消息中提到的用户列表中
  3. 如果是,则让机器人提及消息作者
  4. 最后检查是否所有用户都已做出反应,如果是,请从您的 SQL/Shelve/whatever 存储中删除该消息,这样以后的反应就不会提及作者。