尝试删除反应删除 (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)
(...)
添加回答
举报
0/150
提交
取消