Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
- Fix `ScheduledEvent.subscriber_count` being incremented instead of decremented when a
user leaves the event.
([#3387](https://github.com/Pycord-Development/pycord/pull/3387))
Expand Down
15 changes: 9 additions & 6 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Comment on lines +1211 to +1213

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember doing this for a specific reason, I'll have to take a look

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a worthy note, Copilot is surprisingly right.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but I believe the thread_data there is partial and since in theory we are supposed to have it always in sync I preferred that one.


self.call: MessageCall | None
try:
Expand Down
6 changes: 5 additions & 1 deletion discord/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading