diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b7a7e28ea..f1c8d12311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html); however, insignificant breaking changes do not guarantee a major version bump, see the reasoning [here](https://github.com/modmail-dev/modmail/issues/319). If you're a plugin developer, note the "BREAKING" section. +# Unreleased + +### Fixed +* Confirm thread creation (react to contact) no longer leaves a thread stuck in a "not ready" cache state when the recipient has DMs disabled. The bot now catches `discord.Forbidden` when sending the confirmation prompt, cancels the thread, and clears the cache entry immediately instead of requiring a bot restart. (#3442) + # v4.2.1 ### Added diff --git a/core/thread.py b/core/thread.py index a01bdbeff7..8bc83f7324 100644 --- a/core/thread.py +++ b/core/thread.py @@ -2664,14 +2664,27 @@ async def create( self.bot.config["confirm_thread_creation_deny"], ) ) - confirm = await destination.send( - embed=discord.Embed( - title=self.bot.config["confirm_thread_creation_title"], - description=self.bot.config["confirm_thread_response"], - color=self.bot.main_color, - ), - view=view, - ) + try: + confirm = await destination.send( + embed=discord.Embed( + title=self.bot.config["confirm_thread_creation_title"], + description=self.bot.config["confirm_thread_response"], + color=self.bot.main_color, + ), + view=view, + ) + except discord.Forbidden: + # Recipient has DMs disabled (or otherwise unreachable). Without this, + # the thread would stay stuck in cache in a "not ready" state until a + # bot restart, since view.wait() below would never run. + logger.warning( + "Could not send confirm-thread-creation message to %s, DMs are likely disabled.", + recipient, + ) + thread.cancelled = True + del self.cache[recipient.id] + return thread + await view.wait() if view.value is None: thread.cancelled = True