嗨,我想在发生另一个反应时删除一个反应。例如,如果用户对表情符号1做出了反应但对表情符号2做出了反应,则删除了表情符号1;或者,如果用户对表情符号1做出了反应但对表情符号4做出了反应,则删除了表情符号1。
我正在使用async def on_raw_reaction_add():
事件并定义了我想使用的表情符号,但是如果我这样做了:
await member.add_roles(role, reason='Added role')
await message.remove_reaction(one, user)
await message.remove_reaction(two, user)
await message.remove_reaction(three, user)
这将删除所有表情符号,包括用户选择的表情符号。
这就是我正在使用的东西:
one = "1\N{COMBINING ENCLOSING KEYCAP}"
two = "2\N{COMBINING ENCLOSING KEYCAP}"
three = "3\N{COMBINING ENCLOSING KEYCAP}"
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
message_ids = [649600853048688642, ]
channel = self.bot.get_channel(634023419482079232)
message = await channel.fetch_message(649600853048688642)
user = self.bot.get_user(payload.user_id)
if not payload.guild_id:
return
if payload.message_id not in message_ids:
return
guild = self.bot.get_guild(payload.guild_id) # You need the guild to get the member who reacted
member = guild.get_member(payload.user_id) # Now you have the key part, the member who should receive the role
restricted_role = discord.utils.get(guild.roles, name="Commands Revoked")
role_name = emoji_role_map.get(payload.emoji.name)
if restricted_role in member.roles:
return
if role_name: # None if not found
role = discord.utils.get(guild.roles, name=role_name)
await member.add_roles(role, reason='Added role')
await message.remove_reaction(one, user)
await message.remove_reaction(two, user)
await message.remove_reaction(three, user)
帮助表示赞赏。