首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“RawReactionActionEvent”对象没有属性“member”

“RawReactionActionEvent”对象没有属性“member”
EN

Stack Overflow用户
提问于 2020-06-25 00:21:32
回答 1查看 411关注 0票数 0

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

代码语言:javascript
复制
@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 Bot\cogs\reaction.py\Discord Bot\cogs\reaction.py",第17行,在on_raw_reaction_add await payload.member.add_roles(commands.reaction_role) AttributeError中:'RawReactionActionEvent‘对象没有’RawReactionActionEvent‘属性。

有人能帮帮我吗?这件事已经困扰我两天了,我甚至找不到解决办法

EN

回答 1

Stack Overflow用户

发布于 2020-06-25 09:14:40

我知道,根据文档,discord.RawReactionActionEvent有效负载具有对象成员。但是为什么不让自己变得更容易,并像在on_raw_reaction_remove事件中一样获取成员呢?下面的方法应该是可行的。

代码语言:javascript
复制
@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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62559656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档