From dfa29ae737066afdb29ee2a66d1093b85c98434e Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 14 Nov 2017 15:30:04 -0500 Subject: [PATCH] channel_id and message_id --- reactrestrict/reactrestrict.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/reactrestrict/reactrestrict.py b/reactrestrict/reactrestrict.py index ede39d9..5d6dc9a 100644 --- a/reactrestrict/reactrestrict.py +++ b/reactrestrict/reactrestrict.py @@ -173,7 +173,26 @@ class ReactRestrict: raise LookupError("No role found.") return role + + async def _get_message_from_channel(self, channel_id: int, message_id: int)\ + -> Union[discord.Message, None]: + """ + Tries to find a message by ID in the current guild context. + :param ctx: + :param message_id: + :return: + """ + channel = self.bot.get_channel(channel_id) + try: + return await channel.get_message(message_id) + except discord.NotFound: + pass + except AttributeError: # VoiceChannel object has no attribute 'get_message' + pass + + return None + async def _get_message(self, ctx: commands.Context, message_id: int)\ -> Union[discord.Message, None]: """ @@ -308,11 +327,11 @@ class ReactRestrict: except LookupError: return - for apprroles in roles: + for apprrole in roles: if apprrole in member.roles: return - message = await self._get_message(ctx, message_id) + message = await self._get_message_from_channel(channel_id, message_id) await message.remove_reaction(emoji, member) # try: