diff --git a/CHANGELOG.md b/CHANGELOG.md index e2b278dad9..9a245b7220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#3425](https://github.com/Pycord-Development/pycord/pull/3425)) - Fixed a bug where audio reception would drop after prolonged silence in a voice channel. ([#3436](https://github.com/Pycord-Development/pycord/pull/3436)) +- 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 39df7568da..23b697a857 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1207,13 +1207,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 ca57691d60..f1712a8b04 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