fix error when adding reaction in DM channel

This commit is contained in:
Mylloon 2021-09-20 11:06:59 +02:00
parent f9c02e6c95
commit be47cc43b0
2 changed files with 11 additions and 3 deletions

View file

@ -133,7 +133,9 @@ class ConfrerieDuKassoulait(commands.Cog):
await payload.member.add_roles(payload.member.guild.get_role(self.messageDictAndEmojiToRoles[payload.message_id][payload.emoji.id]))
except:
await payload.member.add_roles(payload.member.guild.get_role(self.messageDictAndEmojiToRoles[payload.message_id][str(payload.emoji)]))
except KeyError:
except KeyError: # mauvais message ou réaction
return
except AttributeError: # reaction en DM
return
@commands.Cog.listener()
@ -148,3 +150,5 @@ class ConfrerieDuKassoulait(commands.Cog):
await member.remove_roles(guild.get_role(self.messageDictAndEmojiToRoles[payload.message_id][str(payload.emoji)]))
except KeyError:
return
except AttributeError: # reaction en DM
return

View file

@ -9,8 +9,12 @@ async def listReaction(client, payload):
"""
if payload.emoji.name in ["⬅️", "🔄", "➡️"]:
if payload.event_type == "REACTION_ADD":
if payload.member: # check car pas de member en DM
if payload.member.bot == True: # vérifie que c'est pas un bot qui a réagit
return False, False
else:
if client.get_user(payload.user_id).bot == True: # vérifie que c'est pas un bot qui a réagit
return False, False
channel = client.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
if message.author.id != client.user.id or len(message.embeds) == 0: # vérification message du bot + au moins 1 embed