【问题标题】:Check if a list of users reacted to message discord.py rewrite检查用户列表是否对消息 discord.py rewrite 做出反应
【发布时间】:2020-03-28 18:12:43
【问题描述】:

我正在尝试为机器人发出命令,当消息中提到的每个人都对机器人的响应做出反应时,它会提到原始消息作者

我试过了

        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

【问题讨论】:

标签: python bots discord discord.py discord.py-rewrite


【解决方案1】:

好的,首先,您需要在当前的实现中考虑一些事情。一方面,您可能希望保存希望机器人在某处观看的消息 ID。不管这是 SQL、Shelve 还是什么

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-20
    • 2021-02-22
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 2019-05-24
    相关资源
    最近更新 更多