From 555ed4e9195aae7b5af742c59125833ce8b01b4c Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sat, 26 Nov 2022 14:40:04 +0400 Subject: Check If Thread Is Closed In wait_for_deletion The wait_for_deletion utility would try to remove reactions from a message after the timeout expires, which would normally be fine. In threads however, they can be closed while waiting for the timeout to expire. In such a case, the bot will try to remove the reactions after the channel has been closed and fail. A special exception was added for this case to do nothing, since this is only a QoL feature. Signed-off-by: Hassan Abouelela --- bot/utils/messages.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bot/utils/messages.py b/bot/utils/messages.py index a5ed84351..cc7e6dccb 100644 --- a/bot/utils/messages.py +++ b/bot/utils/messages.py @@ -98,7 +98,14 @@ async def wait_for_deletion( try: await bot.instance.wait_for('reaction_add', check=check, timeout=timeout) except asyncio.TimeoutError: - await message.clear_reactions() + 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 else: await message.delete() except discord.NotFound: -- cgit v1.2.3