From 35e67d53fce03b3490e6522afb8ab2573e1fc527 Mon Sep 17 00:00:00 2001 From: flifloo Date: Tue, 3 Nov 2020 16:26:19 +0100 Subject: [PATCH] Fix payload with optional member --- extensions/poll.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/extensions/poll.py b/extensions/poll.py index 39ba857..d247a9e 100644 --- a/extensions/poll.py +++ b/extensions/poll.py @@ -63,16 +63,21 @@ class Poll(commands.Cog): @commands.Cog.listener() async def on_raw_reaction_add(self, payload: RawReactionActionEvent): - if not payload.member.bot: + if not payload.member: + user = await self.bot.fetch_user(payload.user_id) + else: + user = payload.member + + if not user.bot: s = db.Session() p = s.query(db.Polls).filter(db.Polls.message == payload.message_id).first() if p: message = await self.bot.get_channel(p.channel).fetch_message(p.message) if str(payload.emoji) not in eval(p.reactions): - await message.remove_reaction(payload.emoji, payload.member) + await message.remove_reaction(payload.emoji, user) elif str(payload.emoji) == "\U0001F5D1": - if payload.member.id != p.author: - await message.remove_reaction(payload.emoji, payload.member) + if user.id != p.author: + await message.remove_reaction(payload.emoji, user) else: await self.close_poll(s, p) elif not p.multi: @@ -80,8 +85,8 @@ class Poll(commands.Cog): for r in message.reactions: if str(r.emoji) != str(payload.emoji): async for u in r.users(): - if u == payload.member: - await r.remove(payload.member) + if u == user: + await r.remove(user) f = True break if f: