【问题标题】:'RawReactionActionEvent' object has no attribute 'member'“RawReactionActionEvent”对象没有属性“成员”
【发布时间】:2020-10-14 23:37:33
【问题描述】:

我遇到了这个问题,但我仍然找不到解决方案,这是代码

@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
    if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
        await payload.member.add_roles(commands.reaction_role)

@commands.Cog.listener()
async def on_raw_reaction_remove(self, payload):
    if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
        guild = self.client.get_guild(payload.guild_id)
        member = guild.get_member(payload.user_id)
        await member.remove_roles(commands.reaction_role)
@commands.command()
async def set_reaction_message(self, ctx, message_id=None, role_id=None):
    for channel in ctx.guild.channels:
        try:
            commands.reaction_message = await channel.fetch_message(int(message_id))
            break

        except:
            pass

问题:文件“c:\Users\MY-NAME\Desktop\Overige en school\Discord Bot\cogs\reaction.py”,第 17 行,on_raw_reaction_add 等待 payload.member.add_roles(commands.reaction_role) AttributeError:“RawReactionActionEvent”对象没有属性“成员”

谁能帮帮我,这已经困扰我 2 天了,我什至找不到解决方案

【问题讨论】:

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


    【解决方案1】:

    我知道根据文档discord.RawReactionActionEvent payload 有对象成员。但是为什么不让自己变得更容易,并以与 on_raw_reaction_remove 事件相同的方式获取成员呢?以下应该可以工作。

    @commands.Cog.listener()
    async def on_raw_reaction_add(self, payload):
        if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
            guild = self.client.get_guild(payload.guild_id)
            member = guild.get_member(payload.user_id)
            await member.add_roles(commands.reaction_role)
    
    @commands.Cog.listener()
    async def on_raw_reaction_remove(self, payload):
        if payload.message_id == commands.reaction_message.id and commands.reaction_role != None:
            guild = self.client.get_guild(payload.guild_id)
            member = guild.get_member(payload.user_id)
            await member.remove_roles(commands.reaction_role)
    
    @commands.command()
    async def set_reaction_message(self, ctx, message_id=None, role_id=None):
        for channel in ctx.guild.channels:
            try:
                commands.reaction_message = await channel.fetch_message(int(message_id))
                break
    
            except:
                pass
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-22
      • 2021-07-28
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多