繁体   English   中英

检查用户列表是否对消息 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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM