From b82ac01d93bc9bbcbd170973492c5b945735d57c Mon Sep 17 00:00:00 2001 From: Bobloy Date: Thu, 2 Nov 2017 17:00:35 -0400 Subject: [PATCH] new get_message (thanks Squid) --- fight/fight.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/fight/fight.py b/fight/fight.py index 26e93c1..e95954d 100644 --- a/fight/fight.py +++ b/fight/fight.py @@ -476,8 +476,26 @@ class Fight: def _getsettings(self, guildid): return self.the_data[guildid]["SETTINGS"] - async def _get_message_from_id(self, channelid, messageid): + async def _get_message_from_id_old(self, channelid, messageid): return await self.bot.get_message(self._get_channel_from_id(channelid), messageid) + + async def _get_message_from_id(self, ctx: commands.Context, 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: + """ + for channel in ctx.guild.channels: + try: + return await channel.get_message(message_id) + except discord.NotFound: + pass + except AttributeError: # VoiceChannel object has no attribute 'get_message' + pass + + return None def _get_message_from_id_recent(self, messageid): return discord.utils.get(self.bot.messages, id=messageid)