“ RawReactionActionEvent”对象没有属性“成员”

时间:2020-06-24 16:21:31

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

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

@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”对象没有属性“ member”

有人可以帮我吗,这困扰了我两天了,我什至找不到解决方法

1 个答案:

答案 0 :(得分:0)

我知道根据文档discord.RawReactionActionEvent,有效负载具有对象成员。但是,为什么不让自己变得更轻松,并以与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