Discord.py on_raw_reaction_remove 成员未找到(删除反应删除角色)

尝试删除反应删除 (on_raw_reaction_remove) 上的角色时,出现成员未找到错误。

它可以将角色添加到成员,但之后无法删除该角色。

我的猜测是它无法正确获取会员的 ID,但我真的不知道如何解决它。

@client.event

async def on_raw_reaction_add(payload):

    message_id = payload.message_id

    if message_id == xxxx:  #ID depends on message

        guild_id = payload.guild_id

        guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds)


        if payload.emoji.name == 'xxx':

            role = discord.utils.get(guild.roles, name="xxx")

        elif payload.emoji.name == 'xxxx':

            role = discord.utils.get(guild.roles, name="xxx")

        else:

            role = discord.utils.get(guild.roles, name = payload.emoji.name)

        

        if role is not None: 

            member = payload.member

            if member is not None:

                await member.add_roles(role)

                print("done")

            else:

                print("member not found")

        else:

            print("role not found.")


@client.event

async def on_raw_reaction_remove(payload):

    message_id = payload.message_id

    if message_id == xxxx:  #ID depends on message

        guild_id = payload.guild_id

        guild = client.get_guild(payload.guild_id)


        if payload.emoji.name == 'wexxed':

            role = discord.utils.get(guild.roles, name="xxxx")

        elif payload.emoji.name == 'xxxx':

            role = discord.utils.get(guild.roles, name="xxx")

        else:

            role = discord.utils.get(guild.roles, name = payload.emoji.name)

        

        if role is not None:

            member = guild.get_member(payload.user_id)

            if member is not None:

                await member.remove_roles(role)

                print("done")

            else:

                print("member not found")

        else:

            print("role not found.")


长风秋雁
浏览 80回答 1
1回答

FFIVE

payload.member仅适用于on_raw_reaction_add(),因此,您必须获取用户,而不是使用它:from discord.utils import get@client.eventasync def on_raw_reaction_remove(payload):    guild = await client.fetch_guild(payload.guild_id)    member = get(guild.members, id=payload.user_id)    (...)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python