diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d407f3758..4bc43cf9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,11 +21,13 @@ These changes are available on the `master` branch, but have not yet been releas ### Fixed -- Fix `TypeError` when accessing `ApplicationCommand.guild_only` or +- Fixed `TypeError` when accessing `ApplicationCommand.guild_only` or `SlashCommandGroup.guild_only` when `contexts` is `None`. ([#3320](https://github.com/Pycord-Development/pycord/pull/3320)) -- Fix `SyntaxWarning` about `return` in a `finally` block raised on Python 3.14+ +- Fixed `SyntaxWarning` about `return` in a `finally` block raised on Python 3.14+ ([#3332](https://github.com/Pycord-Development/pycord/pull/3334)) +- Fixed `AttributeError` when fetching a message from a `PartialMessageable` object that + has a thread. ([#3309](https://github.com/Pycord-Development/pycord/pull/3309)) ### Deprecated diff --git a/discord/message.py b/discord/message.py index e1633aa97e..f5e955b1d5 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1201,13 +1201,16 @@ def __init__( except KeyError: self._poll = None - self.thread: Thread | None - try: - self.thread = Thread( - guild=self.guild, state=self._state, data=data["thread"] + self.thread: Thread | None = None + if thread_data := data.get("thread"): + # When fetching from a PartialMessageable, we don't have a guild so we need to fallback here + guild = self.guild or state._get_guild( + utils._get_as_snowflake(thread_data, "guild_id") ) - except KeyError: - self.thread = None + if guild is not None: + self.thread = guild.get_thread(int(thread_data["id"])) or Thread( + guild=guild, state=self._state, data=thread_data + ) self.call: MessageCall | None try: diff --git a/discord/threads.py b/discord/threads.py index 7d73331c1f..5533a28a8e 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -208,7 +208,11 @@ def _from_data(self, data: ThreadPayload): ] # Here, we try to fill in potentially missing data - if thread := self.guild.get_thread(self.id) and data.pop("_invoke_flag", False): + if ( + self.guild + and (thread := self.guild.get_thread(self.id)) + and data.pop("_invoke_flag", False) + ): self.owner_id = thread.owner_id if self.owner_id is None else self.owner_id self.last_message_id = ( thread.last_message_id