【问题标题】:discordpy - Get list of users who reacted to a specific messagediscordpy - 获取对特定消息做出反应的用户列表
【发布时间】:2019-12-27 05:11:35
【问题描述】:

我正在学习 discordPy,我正在尝试获取对特定消息做出反应的用户列表(姓名/ID)。以下是我的代码:

    async def ga(self, ctx):
        channel = ctx.channel
        users = ""
        async for message in channel.history(limit=200):
            if message.id == '613850569718890495':
                reactions = message.reactions
        async for user in reactions.users():
            users += user.name + ", "
        await ctx.send(content=f"user: {users}")

我没有收到任何错误消息,但我也没有收到任何结果。你能指出我的代码有什么问题吗?谢谢

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

    ID 是整数,而不是字符串,Reaction.usersAyncIteratorMessage.reactions 是常规列表

    channel_id = 12345  # Replace with channel id
    message_id = 613850569718890495  # Note these are ints, not strings
    
    @commands.command()
    async def ga(self, ctx):
        channel = self.bot.get_channel(channel_id)
        message = await channel.fetch_message(message_id)
        users = set()
        for reaction in message.reactions:
            async for user in reaction.users():
                users.add(user)
        await ctx.send(f"users: {', '.join(user.name for user in users)}")
    

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 2018-08-18
      • 2021-10-05
      • 2021-03-05
      • 2021-09-10
      • 2021-06-24
      • 2019-05-24
      • 1970-01-01
      • 2021-01-31
      相关资源
      最近更新 更多