From be47cc43b0cebc7b7808f110fc1d4a0abeacd1e4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 20 Sep 2021 11:06:59 +0200 Subject: [PATCH] fix error when adding reaction in DM channel --- src/cogs/confreriedukassoulait.py | 6 +++++- src/utils/page.py | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cogs/confreriedukassoulait.py b/src/cogs/confreriedukassoulait.py index 91a5de1..256e503 100644 --- a/src/cogs/confreriedukassoulait.py +++ b/src/cogs/confreriedukassoulait.py @@ -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 diff --git a/src/utils/page.py b/src/utils/page.py index 00e2c53..9e5c027 100644 --- a/src/utils/page.py +++ b/src/utils/page.py @@ -9,8 +9,12 @@ async def listReaction(client, payload): """ if payload.emoji.name in ["⬅️", "🔄", "➡️"]: if payload.event_type == "REACTION_ADD": - if payload.member.bot == True: # vérifie que c'est pas un bot qui a réagit - return False, False + 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