diff options
| author | 2020-07-08 21:39:17 +0300 | |
|---|---|---|
| committer | 2020-07-08 21:39:17 +0300 | |
| commit | a201e76c805fe69e70e39bbd8a24f81ee5d0fe9b (patch) | |
| tree | 0c4409dc87f08f2d7051889b1d43916333220003 | |
| parent | Merge branch 'master' into help-channels-pin (diff) | |
Help Channels: Simplify unpinning
Remove complex None checking message fetching and replace it with `bot.http.unpin_message` and catch exception when message don't exist.
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/help_channels.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py index bb97759ee..9313efc67 100644 --- a/bot/cogs/help_channels.py +++ b/bot/cogs/help_channels.py @@ -554,19 +554,12 @@ class HelpChannels(Scheduler, commands.Cog): """ msg_id = await self.question_messages.pop(channel.id) - # When message ID exist in cache, try to get it from cache first. When this fail, use API request. - # When this return 404, this mean that message is deleted and can't be unpinned. - if msg_id: - msg = discord.utils.get(self.bot.cached_messages, id=msg_id) - if msg is None: - try: - msg = await channel.fetch_message(msg_id) - except discord.NotFound: - log.debug(f"Can't unpin message {msg_id} because this is deleted.") - - # When we got message, then unpin it - if msg: - await msg.unpin() + try: + await self.bot.http.unpin_message(channel.id, msg_id) + except discord.HTTPException: + log.trace(f"Message {msg_id} don't exist, can't unpin.") + else: + log.trace(f"Unpinned message {msg_id}.") log.info(f"Moving #{channel} ({channel.id}) to the Dormant category.") |