为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

长风秋雁 2023-12-29 15:24:06
尝试删除反应删除 (on_raw_reaction_remove) 上的角色时,出现成员未找到错误。它可以将角色添加到成员,但之后无法删除该角色。我的猜测是它无法正确获取会员的 ID,但我真的不知道如何解决它。@client.eventasync 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.eventasync 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.")
查看完整描述

1 回答

?
FFIVE

TA贡献1797条经验 获得超6个赞

payload.member仅适用于on_raw_reaction_add(),因此,您必须获取用户,而不是使用它:

from discord.utils import get


@client.event

async def on_raw_reaction_remove(payload):

    guild = await client.fetch_guild(payload.guild_id)

    member = get(guild.members, id=payload.user_id)

    (...)


查看完整回答
反对 回复 2023-12-29
  • 1 回答
  • 0 关注
  • 79 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信