尝试删除反应删除 (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.")
FFIVE
相关分类