Skip to content

Commit 5d4175e

Browse files
13-PrabhatStephenDaDev
authored andcommitted
fix: handle Forbidden when sending confirm-thread-creation DM (#3442)
1 parent 1da6d46 commit 5d4175e

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
77
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.
88

9+
# Unreleased
10+
11+
### Fixed
12+
* 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)
13+
914
# v4.2.1
1015

1116
### Added

core/thread.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,14 +2664,27 @@ async def create(
26642664
self.bot.config["confirm_thread_creation_deny"],
26652665
)
26662666
)
2667-
confirm = await destination.send(
2668-
embed=discord.Embed(
2669-
title=self.bot.config["confirm_thread_creation_title"],
2670-
description=self.bot.config["confirm_thread_response"],
2671-
color=self.bot.main_color,
2672-
),
2673-
view=view,
2674-
)
2667+
try:
2668+
confirm = await destination.send(
2669+
embed=discord.Embed(
2670+
title=self.bot.config["confirm_thread_creation_title"],
2671+
description=self.bot.config["confirm_thread_response"],
2672+
color=self.bot.main_color,
2673+
),
2674+
view=view,
2675+
)
2676+
except discord.Forbidden:
2677+
# Recipient has DMs disabled (or otherwise unreachable). Without this,
2678+
# the thread would stay stuck in cache in a "not ready" state until a
2679+
# bot restart, since view.wait() below would never run.
2680+
logger.warning(
2681+
"Could not send confirm-thread-creation message to %s, DMs are likely disabled.",
2682+
recipient,
2683+
)
2684+
thread.cancelled = True
2685+
del self.cache[recipient.id]
2686+
return thread
2687+
26752688
await view.wait()
26762689
if view.value is None:
26772690
thread.cancelled = True

0 commit comments

Comments
 (0)