diff options
author | 2022-11-26 16:12:42 +0400 | |
---|---|---|
committer | 2022-11-26 16:28:48 +0400 | |
commit | 8cfa7ed5b39b85e432420c5749c0fe1569e2d2cb (patch) | |
tree | 6491c9b2291fee2b9fa26776d9cd65ec580c0558 | |
parent | Handle Images As Starter Messages (diff) |
Refactor Thread Error Catching
Co-authored-by: Boris Muratov <[email protected]>
Co-authored-by: Amrou Bellalouna <[email protected]>
Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r-- | bot/exts/help_channels/_channel.py | 6 | ||||
-rw-r--r-- | bot/pagination.py | 13 | ||||
-rw-r--r-- | bot/utils/messages.py | 15 |
3 files changed, 17 insertions, 17 deletions
diff --git a/bot/exts/help_channels/_channel.py b/bot/exts/help_channels/_channel.py index b9a79a476..5fc39b623 100644 --- a/bot/exts/help_channels/_channel.py +++ b/bot/exts/help_channels/_channel.py @@ -132,10 +132,8 @@ async def help_thread_opened(opened_thread: discord.Thread, *, reopen: bool = Fa try: await opened_thread.starter_message.pin() except discord.HTTPException as e: - if e.code == 10008: - # The message was not found, most likely deleted - pass - else: + # Suppress if the message was not found, most likely deleted + if e.code != 10008: raise e await send_opened_post_message(opened_thread) diff --git a/bot/pagination.py b/bot/pagination.py index 5b96d8fbb..0ef5808cc 100644 --- a/bot/pagination.py +++ b/bot/pagination.py @@ -303,7 +303,12 @@ class LinePaginator(Paginator): return await message.delete() elif reaction.emoji in PAGINATION_EMOJI: total_pages = len(paginator.pages) - await message.remove_reaction(reaction.emoji, user) + try: + await message.remove_reaction(reaction.emoji, user) + except discord.HTTPException as e: + # Suppress if trying to act on an archived thread. + if e.code != 50083: + raise e if reaction.emoji == FIRST_EMOJI: current_page = 0 @@ -347,8 +352,6 @@ class LinePaginator(Paginator): try: await message.clear_reactions() except discord.HTTPException as e: - if e.code == 50083: - # Trying to act on an archived thread, just ignore - pass - else: + # Suppress if trying to act on an archived thread. + if e.code != 50083: raise e diff --git a/bot/utils/messages.py b/bot/utils/messages.py index cc7e6dccb..8a968f659 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -98,19 +98,18 @@ async def wait_for_deletion( try: await bot.instance.wait_for('reaction_add', check=check, timeout=timeout) except asyncio.TimeoutError: - try: - await message.clear_reactions() - except discord.HTTPException as e: - if isinstance(message.channel, discord.Thread): - # Threads might not be accessible by the time we try to remove the reaction. - pass - else: - raise e + await message.clear_reactions() else: await message.delete() + except discord.NotFound: log.trace(f"wait_for_deletion: message {message.id} deleted prematurely.") + except discord.HTTPException: + if not isinstance(message.channel, discord.Thread): + # Threads might not be accessible by the time the timeout expires + raise + async def send_attachments( message: discord.Message, |