From 30a788bcddb1e27e751635429317b91d10afb970 Mon Sep 17 00:00:00 2001 From: Paillat-dev Date: Sun, 19 Jul 2026 22:58:56 +0200 Subject: [PATCH 1/8] fix: Guard for None guild --- discord/threads.py | 50 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/discord/threads.py b/discord/threads.py index 81d973775f..2b62a2414f 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -207,7 +207,7 @@ 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 @@ -462,7 +462,7 @@ def permissions_for(self, obj: Member | Role, /) -> Permissions: return parent.permissions_for(obj) async def delete_messages( - self, messages: Iterable[Snowflake], *, reason: str | None = None + self, messages: Iterable[Snowflake], *, reason: str | None = None ) -> None: """|coro| @@ -518,16 +518,16 @@ async def delete_messages( await self._state.http.delete_messages(self.id, message_ids, reason=reason) async def purge( - self, - *, - limit: int | None = 100, - check: Callable[[Message], bool] = MISSING, - before: SnowflakeTime | None = None, - after: SnowflakeTime | None = None, - around: SnowflakeTime | None = None, - oldest_first: bool | None = False, - bulk: bool = True, - reason: str | None = None, + self, + *, + limit: int | None = 100, + check: Callable[[Message], bool] = MISSING, + before: SnowflakeTime | None = None, + after: SnowflakeTime | None = None, + around: SnowflakeTime | None = None, + oldest_first: bool | None = False, + bulk: bool = True, + reason: str | None = None, ) -> list[Message]: """|coro| @@ -599,19 +599,19 @@ def is_me(m): ) async def edit( - self, - *, - name: str = MISSING, - archived: bool = MISSING, - locked: bool = MISSING, - invitable: bool = MISSING, - slowmode_delay: int = MISSING, - auto_archive_duration: ( - ThreadArchiveDuration | ThreadArchiveDurationEnum - ) = MISSING, - pinned: bool = MISSING, - applied_tags: list[ForumTag] = MISSING, - reason: str | None = None, + self, + *, + name: str = MISSING, + archived: bool = MISSING, + locked: bool = MISSING, + invitable: bool = MISSING, + slowmode_delay: int = MISSING, + auto_archive_duration: ( + ThreadArchiveDuration | ThreadArchiveDurationEnum + ) = MISSING, + pinned: bool = MISSING, + applied_tags: list[ForumTag] = MISSING, + reason: str | None = None, ) -> Thread: """|coro| From 7798e0b3e3eb35c441c840e5ddfc9be05c911974 Mon Sep 17 00:00:00 2001 From: Paillat-dev Date: Sun, 19 Jul 2026 23:07:21 +0200 Subject: [PATCH 2/8] fix: Strill brokeb --- discord/message.py | 210 +++++++++++++++++++++++---------------------- 1 file changed, 107 insertions(+), 103 deletions(-) diff --git a/discord/message.py b/discord/message.py index 5dffbbe668..40503b8d34 100644 --- a/discord/message.py +++ b/discord/message.py @@ -288,12 +288,12 @@ def __str__(self) -> str: return self.url or "" async def save( - self, - fp: io.BufferedIOBase | PathLike, - *, - seek_begin: bool = True, - use_cached: bool = False, - chunksize: int | None = None, + self, + fp: io.BufferedIOBase | PathLike, + *, + seek_begin: bool = True, + use_cached: bool = False, + chunksize: int | None = None, ) -> int: """|coro| @@ -393,7 +393,7 @@ async def read(self, *, use_cached: bool = False) -> bytes: return data async def read_chunked( - self, chunksize: int, *, use_cached: bool = False + self, chunksize: int, *, use_cached: bool = False ) -> AsyncGenerator[bytes]: """|coro| @@ -586,13 +586,13 @@ class MessageReference: ) def __init__( - self, - *, - message_id: int, - channel_id: int, - guild_id: int | None = None, - fail_if_not_exists: bool = True, - type: MessageReferenceType = MessageReferenceType.default, + self, + *, + message_id: int, + channel_id: int, + guild_id: int | None = None, + fail_if_not_exists: bool = True, + type: MessageReferenceType = MessageReferenceType.default, ): self._state: ConnectionState | None = None self.resolved: Message | DeletedReferencedMessage | None = None @@ -604,12 +604,12 @@ def __init__( @classmethod def with_state( - cls: type[MR], state: ConnectionState, data: MessageReferencePayload + cls: type[MR], state: ConnectionState, data: MessageReferencePayload ) -> MR: self = cls.__new__(cls) self.type = ( - try_enum(MessageReferenceType, data.get("type")) - or MessageReferenceType.default + try_enum(MessageReferenceType, data.get("type")) + or MessageReferenceType.default ) self.message_id = utils._get_as_snowflake(data, "message_id") self.channel_id = utils._get_as_snowflake(data, "channel_id") @@ -621,11 +621,11 @@ def with_state( @classmethod def from_message( - cls: type[MR], - message: Message, - *, - fail_if_not_exists: bool = True, - type: MessageReferenceType = MessageReferenceType.default, + cls: type[MR], + message: Message, + *, + fail_if_not_exists: bool = True, + type: MessageReferenceType = MessageReferenceType.default, ) -> MR: """Creates a :class:`MessageReference` from an existing :class:`~discord.Message`. @@ -767,27 +767,27 @@ class ForwardedMessage: """ def __init__( - self, - *, - state: ConnectionState, - reference: MessageReference, - data: ForwardedMessagePayload, + self, + *, + state: ConnectionState, + reference: MessageReference, + data: ForwardedMessagePayload, ): self._state: ConnectionState = state self._reference = reference self.id: int = reference.message_id self.channel = state.get_channel(reference.channel_id) or ( - reference.channel_id - and PartialMessageable( - state=state, - id=reference.channel_id, - ) + reference.channel_id + and PartialMessageable( + state=state, + id=reference.channel_id, + ) ) self.guild = state._get_guild(reference.guild_id) or ( - reference.guild_id and Object(reference.guild_id) + reference.guild_id and Object(reference.guild_id) ) self.original_message = state._get_message(self.id) or ( - self.id and self.channel.get_partial_message(self.id) + self.id and self.channel.get_partial_message(self.id) ) self.content: str = data["content"] self.embeds: list[Embed] = [Embed.from_dict(a) for a in data["embeds"]] @@ -844,11 +844,11 @@ class MessageSnapshot: """ def __init__( - self, - *, - state: ConnectionState, - reference: MessageReference, - data: MessageSnapshotPayload, + self, + *, + state: ConnectionState, + reference: MessageReference, + data: MessageSnapshotPayload, ): self._state: ConnectionState = state self.message: ForwardedMessage | None @@ -881,10 +881,10 @@ class MessagePin: """ def __init__( - self, - state: ConnectionState, - channel: MessageableChannel, - data: MessagePinPayload, + self, + state: ConnectionState, + channel: MessageableChannel, + data: MessagePinPayload, ): self._state: ConnectionState = state self._pinned_at: datetime.datetime = utils.parse_time(data["pinned_at"]) @@ -1099,11 +1099,11 @@ class Message(Hashable): role_mentions: list[Role] def __init__( - self, - *, - state: ConnectionState, - channel: MessageableChannel, - data: MessagePayload, + self, + *, + state: ConnectionState, + channel: MessageableChannel, + data: MessagePayload, ): self._state: ConnectionState = state self._raw_data: MessagePayload = data @@ -1203,13 +1203,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: @@ -1256,7 +1259,7 @@ def _add_reaction(self, data, emoji, user_id) -> Reaction: return reaction def _remove_reaction( - self, data: ReactionPayload, emoji: EmojiInputType, user_id: int + self, data: ReactionPayload, emoji: EmojiInputType, user_id: int ) -> Reaction: reaction = utils.find(lambda r: r.emoji == emoji, self.reactions) @@ -1379,7 +1382,7 @@ def _handle_components(self, components: list[ComponentPayload]): self.components = [_component_factory(d, state=self._state) for d in components] def _rebind_cached_references( - self, new_guild: Guild, new_channel: TextChannel | Thread + self, new_guild: Guild, new_channel: TextChannel | Thread ) -> None: self.guild = new_guild self.channel = new_channel @@ -1689,7 +1692,7 @@ def system_content(self) -> str: ) async def delete( - self, *, delay: float | None = None, reason: str | None = None + self, *, delay: float | None = None, reason: str | None = None ) -> None: """|coro| @@ -1729,34 +1732,35 @@ async def delete( @overload async def edit( - self, - *, - content: str | None = ..., - embed: Embed | None = ..., - embeds: list[Embed] = ..., - file: File | None = ..., - files: list[File] | None = ..., - attachments: list[Attachment] = ..., - suppress: bool = ..., - suppress_embeds: bool = ..., - delete_after: float | None = ..., - allowed_mentions: AllowedMentions | None = ..., - view: BaseView | None = ..., - ) -> Message: ... + self, + *, + content: str | None = ..., + embed: Embed | None = ..., + embeds: list[Embed] = ..., + file: File | None = ..., + files: list[File] | None = ..., + attachments: list[Attachment] = ..., + suppress: bool = ..., + suppress_embeds: bool = ..., + delete_after: float | None = ..., + allowed_mentions: AllowedMentions | None = ..., + view: BaseView | None = ..., + ) -> Message: + ... async def edit( - self, - content: str | None = MISSING, - embed: Embed | None = MISSING, - embeds: list[Embed] = MISSING, - file: Sequence[File] = MISSING, - files: list[Sequence[File]] = MISSING, - attachments: list[Attachment] = MISSING, - suppress: bool = MISSING, - suppress_embeds: bool = MISSING, - delete_after: float | None = None, - allowed_mentions: AllowedMentions | None = MISSING, - view: BaseView | None = MISSING, + self, + content: str | None = MISSING, + embed: Embed | None = MISSING, + embeds: list[Embed] = MISSING, + file: Sequence[File] = MISSING, + files: list[Sequence[File]] = MISSING, + attachments: list[Attachment] = MISSING, + suppress: bool = MISSING, + suppress_embeds: bool = MISSING, + delete_after: float | None = None, + allowed_mentions: AllowedMentions | None = MISSING, + view: BaseView | None = MISSING, ) -> Message: """|coro| @@ -1858,8 +1862,8 @@ async def edit( if allowed_mentions is MISSING: if ( - self._state.allowed_mentions is not None - and self.author.id == self._state.self_id + self._state.allowed_mentions is not None + and self.author.id == self._state.self_id ): payload["allowed_mentions"] = self._state.allowed_mentions.to_dict() elif allowed_mentions is not None: @@ -2036,7 +2040,7 @@ async def add_reaction(self, emoji: EmojiInputType) -> None: await self._state.http.add_reaction(self.channel.id, self.id, emoji) async def remove_reaction( - self, emoji: EmojiInputType | Reaction, member: Snowflake + self, emoji: EmojiInputType | Reaction, member: Snowflake ) -> None: """|coro| @@ -2126,11 +2130,11 @@ async def clear_reactions(self) -> None: await self._state.http.clear_reactions(self.channel.id, self.id) async def create_thread( - self, - *, - name: str, - auto_archive_duration: ThreadArchiveDuration = MISSING, - slowmode_delay: int = MISSING, + self, + *, + name: str, + auto_archive_duration: ThreadArchiveDuration = MISSING, + slowmode_delay: int = MISSING, ) -> Thread: """|coro| @@ -2180,7 +2184,7 @@ async def create_thread( self.id, name=name, auto_archive_duration=auto_archive_duration - or default_auto_archive_duration, + or default_auto_archive_duration, rate_limit_per_user=slowmode_delay or 0, ) @@ -2214,7 +2218,7 @@ async def reply(self, content: str | None = None, **kwargs) -> Message: return await self.channel.send(content, reference=self.to_reference(), **kwargs) async def forward_to( - self, channel: MessageableChannel | PartialMessageableChannel, **kwargs + self, channel: MessageableChannel | PartialMessageableChannel, **kwargs ) -> Message: """|coro| @@ -2277,7 +2281,7 @@ async def end_poll(self) -> Message: return message def to_reference( - self, *, fail_if_not_exists: bool = True, type: MessageReferenceType = None + self, *, fail_if_not_exists: bool = True, type: MessageReferenceType = None ) -> MessageReference: """Creates a :class:`~discord.MessageReference` from the current message. @@ -2307,7 +2311,7 @@ def to_reference( ) def to_message_reference_dict( - self, type: MessageReferenceType = None + self, type: MessageReferenceType = None ) -> MessageReferencePayload: data: MessageReferencePayload = { "message_id": self.id, @@ -2405,14 +2409,14 @@ class PartialMessage(Hashable): def __init__(self, *, channel: PartialMessageableChannel, id: int): if channel.type not in ( - ChannelType.text, - ChannelType.voice, - ChannelType.stage_voice, - ChannelType.news, - ChannelType.private, - ChannelType.news_thread, - ChannelType.public_thread, - ChannelType.private_thread, + ChannelType.text, + ChannelType.voice, + ChannelType.stage_voice, + ChannelType.news, + ChannelType.private, + ChannelType.news_thread, + ChannelType.public_thread, + ChannelType.private_thread, ) and not isinstance(channel, PartialMessageable): raise TypeError( "Expected TextChannel, VoiceChannel, StageChannel, DMChannel, Thread or PartialMessageable not" From dabd9dd6815e1f6ff8e5f3deee07c9bbc963a599 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 19 Jul 2026 21:15:21 +0000 Subject: [PATCH 3/8] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/message.py | 195 ++++++++++++++++++++++----------------------- discord/threads.py | 54 +++++++------ 2 files changed, 126 insertions(+), 123 deletions(-) diff --git a/discord/message.py b/discord/message.py index 40503b8d34..bd86a4a771 100644 --- a/discord/message.py +++ b/discord/message.py @@ -288,12 +288,12 @@ def __str__(self) -> str: return self.url or "" async def save( - self, - fp: io.BufferedIOBase | PathLike, - *, - seek_begin: bool = True, - use_cached: bool = False, - chunksize: int | None = None, + self, + fp: io.BufferedIOBase | PathLike, + *, + seek_begin: bool = True, + use_cached: bool = False, + chunksize: int | None = None, ) -> int: """|coro| @@ -393,7 +393,7 @@ async def read(self, *, use_cached: bool = False) -> bytes: return data async def read_chunked( - self, chunksize: int, *, use_cached: bool = False + self, chunksize: int, *, use_cached: bool = False ) -> AsyncGenerator[bytes]: """|coro| @@ -586,13 +586,13 @@ class MessageReference: ) def __init__( - self, - *, - message_id: int, - channel_id: int, - guild_id: int | None = None, - fail_if_not_exists: bool = True, - type: MessageReferenceType = MessageReferenceType.default, + self, + *, + message_id: int, + channel_id: int, + guild_id: int | None = None, + fail_if_not_exists: bool = True, + type: MessageReferenceType = MessageReferenceType.default, ): self._state: ConnectionState | None = None self.resolved: Message | DeletedReferencedMessage | None = None @@ -604,12 +604,12 @@ def __init__( @classmethod def with_state( - cls: type[MR], state: ConnectionState, data: MessageReferencePayload + cls: type[MR], state: ConnectionState, data: MessageReferencePayload ) -> MR: self = cls.__new__(cls) self.type = ( - try_enum(MessageReferenceType, data.get("type")) - or MessageReferenceType.default + try_enum(MessageReferenceType, data.get("type")) + or MessageReferenceType.default ) self.message_id = utils._get_as_snowflake(data, "message_id") self.channel_id = utils._get_as_snowflake(data, "channel_id") @@ -621,11 +621,11 @@ def with_state( @classmethod def from_message( - cls: type[MR], - message: Message, - *, - fail_if_not_exists: bool = True, - type: MessageReferenceType = MessageReferenceType.default, + cls: type[MR], + message: Message, + *, + fail_if_not_exists: bool = True, + type: MessageReferenceType = MessageReferenceType.default, ) -> MR: """Creates a :class:`MessageReference` from an existing :class:`~discord.Message`. @@ -767,27 +767,27 @@ class ForwardedMessage: """ def __init__( - self, - *, - state: ConnectionState, - reference: MessageReference, - data: ForwardedMessagePayload, + self, + *, + state: ConnectionState, + reference: MessageReference, + data: ForwardedMessagePayload, ): self._state: ConnectionState = state self._reference = reference self.id: int = reference.message_id self.channel = state.get_channel(reference.channel_id) or ( - reference.channel_id - and PartialMessageable( - state=state, - id=reference.channel_id, - ) + reference.channel_id + and PartialMessageable( + state=state, + id=reference.channel_id, + ) ) self.guild = state._get_guild(reference.guild_id) or ( - reference.guild_id and Object(reference.guild_id) + reference.guild_id and Object(reference.guild_id) ) self.original_message = state._get_message(self.id) or ( - self.id and self.channel.get_partial_message(self.id) + self.id and self.channel.get_partial_message(self.id) ) self.content: str = data["content"] self.embeds: list[Embed] = [Embed.from_dict(a) for a in data["embeds"]] @@ -844,11 +844,11 @@ class MessageSnapshot: """ def __init__( - self, - *, - state: ConnectionState, - reference: MessageReference, - data: MessageSnapshotPayload, + self, + *, + state: ConnectionState, + reference: MessageReference, + data: MessageSnapshotPayload, ): self._state: ConnectionState = state self.message: ForwardedMessage | None @@ -881,10 +881,10 @@ class MessagePin: """ def __init__( - self, - state: ConnectionState, - channel: MessageableChannel, - data: MessagePinPayload, + self, + state: ConnectionState, + channel: MessageableChannel, + data: MessagePinPayload, ): self._state: ConnectionState = state self._pinned_at: datetime.datetime = utils.parse_time(data["pinned_at"]) @@ -1099,11 +1099,11 @@ class Message(Hashable): role_mentions: list[Role] def __init__( - self, - *, - state: ConnectionState, - channel: MessageableChannel, - data: MessagePayload, + self, + *, + state: ConnectionState, + channel: MessageableChannel, + data: MessagePayload, ): self._state: ConnectionState = state self._raw_data: MessagePayload = data @@ -1259,7 +1259,7 @@ def _add_reaction(self, data, emoji, user_id) -> Reaction: return reaction def _remove_reaction( - self, data: ReactionPayload, emoji: EmojiInputType, user_id: int + self, data: ReactionPayload, emoji: EmojiInputType, user_id: int ) -> Reaction: reaction = utils.find(lambda r: r.emoji == emoji, self.reactions) @@ -1382,7 +1382,7 @@ def _handle_components(self, components: list[ComponentPayload]): self.components = [_component_factory(d, state=self._state) for d in components] def _rebind_cached_references( - self, new_guild: Guild, new_channel: TextChannel | Thread + self, new_guild: Guild, new_channel: TextChannel | Thread ) -> None: self.guild = new_guild self.channel = new_channel @@ -1692,7 +1692,7 @@ def system_content(self) -> str: ) async def delete( - self, *, delay: float | None = None, reason: str | None = None + self, *, delay: float | None = None, reason: str | None = None ) -> None: """|coro| @@ -1732,35 +1732,34 @@ async def delete( @overload async def edit( - self, - *, - content: str | None = ..., - embed: Embed | None = ..., - embeds: list[Embed] = ..., - file: File | None = ..., - files: list[File] | None = ..., - attachments: list[Attachment] = ..., - suppress: bool = ..., - suppress_embeds: bool = ..., - delete_after: float | None = ..., - allowed_mentions: AllowedMentions | None = ..., - view: BaseView | None = ..., - ) -> Message: - ... + self, + *, + content: str | None = ..., + embed: Embed | None = ..., + embeds: list[Embed] = ..., + file: File | None = ..., + files: list[File] | None = ..., + attachments: list[Attachment] = ..., + suppress: bool = ..., + suppress_embeds: bool = ..., + delete_after: float | None = ..., + allowed_mentions: AllowedMentions | None = ..., + view: BaseView | None = ..., + ) -> Message: ... async def edit( - self, - content: str | None = MISSING, - embed: Embed | None = MISSING, - embeds: list[Embed] = MISSING, - file: Sequence[File] = MISSING, - files: list[Sequence[File]] = MISSING, - attachments: list[Attachment] = MISSING, - suppress: bool = MISSING, - suppress_embeds: bool = MISSING, - delete_after: float | None = None, - allowed_mentions: AllowedMentions | None = MISSING, - view: BaseView | None = MISSING, + self, + content: str | None = MISSING, + embed: Embed | None = MISSING, + embeds: list[Embed] = MISSING, + file: Sequence[File] = MISSING, + files: list[Sequence[File]] = MISSING, + attachments: list[Attachment] = MISSING, + suppress: bool = MISSING, + suppress_embeds: bool = MISSING, + delete_after: float | None = None, + allowed_mentions: AllowedMentions | None = MISSING, + view: BaseView | None = MISSING, ) -> Message: """|coro| @@ -1862,8 +1861,8 @@ async def edit( if allowed_mentions is MISSING: if ( - self._state.allowed_mentions is not None - and self.author.id == self._state.self_id + self._state.allowed_mentions is not None + and self.author.id == self._state.self_id ): payload["allowed_mentions"] = self._state.allowed_mentions.to_dict() elif allowed_mentions is not None: @@ -2040,7 +2039,7 @@ async def add_reaction(self, emoji: EmojiInputType) -> None: await self._state.http.add_reaction(self.channel.id, self.id, emoji) async def remove_reaction( - self, emoji: EmojiInputType | Reaction, member: Snowflake + self, emoji: EmojiInputType | Reaction, member: Snowflake ) -> None: """|coro| @@ -2130,11 +2129,11 @@ async def clear_reactions(self) -> None: await self._state.http.clear_reactions(self.channel.id, self.id) async def create_thread( - self, - *, - name: str, - auto_archive_duration: ThreadArchiveDuration = MISSING, - slowmode_delay: int = MISSING, + self, + *, + name: str, + auto_archive_duration: ThreadArchiveDuration = MISSING, + slowmode_delay: int = MISSING, ) -> Thread: """|coro| @@ -2184,7 +2183,7 @@ async def create_thread( self.id, name=name, auto_archive_duration=auto_archive_duration - or default_auto_archive_duration, + or default_auto_archive_duration, rate_limit_per_user=slowmode_delay or 0, ) @@ -2218,7 +2217,7 @@ async def reply(self, content: str | None = None, **kwargs) -> Message: return await self.channel.send(content, reference=self.to_reference(), **kwargs) async def forward_to( - self, channel: MessageableChannel | PartialMessageableChannel, **kwargs + self, channel: MessageableChannel | PartialMessageableChannel, **kwargs ) -> Message: """|coro| @@ -2281,7 +2280,7 @@ async def end_poll(self) -> Message: return message def to_reference( - self, *, fail_if_not_exists: bool = True, type: MessageReferenceType = None + self, *, fail_if_not_exists: bool = True, type: MessageReferenceType = None ) -> MessageReference: """Creates a :class:`~discord.MessageReference` from the current message. @@ -2311,7 +2310,7 @@ def to_reference( ) def to_message_reference_dict( - self, type: MessageReferenceType = None + self, type: MessageReferenceType = None ) -> MessageReferencePayload: data: MessageReferencePayload = { "message_id": self.id, @@ -2409,14 +2408,14 @@ class PartialMessage(Hashable): def __init__(self, *, channel: PartialMessageableChannel, id: int): if channel.type not in ( - ChannelType.text, - ChannelType.voice, - ChannelType.stage_voice, - ChannelType.news, - ChannelType.private, - ChannelType.news_thread, - ChannelType.public_thread, - ChannelType.private_thread, + ChannelType.text, + ChannelType.voice, + ChannelType.stage_voice, + ChannelType.news, + ChannelType.private, + ChannelType.news_thread, + ChannelType.public_thread, + ChannelType.private_thread, ) and not isinstance(channel, PartialMessageable): raise TypeError( "Expected TextChannel, VoiceChannel, StageChannel, DMChannel, Thread or PartialMessageable not" diff --git a/discord/threads.py b/discord/threads.py index 2b62a2414f..1d6d126b2e 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -207,7 +207,11 @@ def _from_data(self, data: ThreadPayload): ] # Here, we try to fill in potentially missing data - if self.guild and (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 @@ -462,7 +466,7 @@ def permissions_for(self, obj: Member | Role, /) -> Permissions: return parent.permissions_for(obj) async def delete_messages( - self, messages: Iterable[Snowflake], *, reason: str | None = None + self, messages: Iterable[Snowflake], *, reason: str | None = None ) -> None: """|coro| @@ -518,16 +522,16 @@ async def delete_messages( await self._state.http.delete_messages(self.id, message_ids, reason=reason) async def purge( - self, - *, - limit: int | None = 100, - check: Callable[[Message], bool] = MISSING, - before: SnowflakeTime | None = None, - after: SnowflakeTime | None = None, - around: SnowflakeTime | None = None, - oldest_first: bool | None = False, - bulk: bool = True, - reason: str | None = None, + self, + *, + limit: int | None = 100, + check: Callable[[Message], bool] = MISSING, + before: SnowflakeTime | None = None, + after: SnowflakeTime | None = None, + around: SnowflakeTime | None = None, + oldest_first: bool | None = False, + bulk: bool = True, + reason: str | None = None, ) -> list[Message]: """|coro| @@ -599,19 +603,19 @@ def is_me(m): ) async def edit( - self, - *, - name: str = MISSING, - archived: bool = MISSING, - locked: bool = MISSING, - invitable: bool = MISSING, - slowmode_delay: int = MISSING, - auto_archive_duration: ( - ThreadArchiveDuration | ThreadArchiveDurationEnum - ) = MISSING, - pinned: bool = MISSING, - applied_tags: list[ForumTag] = MISSING, - reason: str | None = None, + self, + *, + name: str = MISSING, + archived: bool = MISSING, + locked: bool = MISSING, + invitable: bool = MISSING, + slowmode_delay: int = MISSING, + auto_archive_duration: ( + ThreadArchiveDuration | ThreadArchiveDurationEnum + ) = MISSING, + pinned: bool = MISSING, + applied_tags: list[ForumTag] = MISSING, + reason: str | None = None, ) -> Thread: """|coro| From a1a4a55e5e70a196498ae58c837a127ad846d5ed Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Sat, 22 Aug 2026 15:34:03 +0300 Subject: [PATCH 4/8] add changelog entry Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d407f3758..d7d5e08bed 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` that has a thread. + ([#3309](https://github.com/Pycord-Development/pycord/pull/3309)) ### Deprecated From 90d13a3b48f9c410f7da98c529d1bd4be2e3e610 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 12:34:33 +0000 Subject: [PATCH 5/8] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7d5e08bed..cdc18ad37e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#3320](https://github.com/Pycord-Development/pycord/pull/3320)) - 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` that has a thread. - ([#3309](https://github.com/Pycord-Development/pycord/pull/3309)) +- Fixed `AttributeError` when fetching a message from a `PartialMessageable` that has a + thread. ([#3309](https://github.com/Pycord-Development/pycord/pull/3309)) ### Deprecated From 91808313cd6ed31d78facc9fe6ff744345baf917 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 2 Sep 2026 15:08:47 +0200 Subject: [PATCH 6/8] Update discord/message.py Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Paillat --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index c9ce91088e..f5e955b1d5 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1203,7 +1203,7 @@ def __init__( 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 + # 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") ) From 94c3a19617d1e6a630dd7f73b074e5d1c6717b6b Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 2 Sep 2026 15:09:00 +0200 Subject: [PATCH 7/8] Update CHANGELOG.md Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Paillat --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdc18ad37e..bdf138b96b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#3320](https://github.com/Pycord-Development/pycord/pull/3320)) - 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` that has a +- Fixed `AttributeError` when fetching a message from a `PartialMessageable` object that has a thread. ([#3309](https://github.com/Pycord-Development/pycord/pull/3309)) ### Deprecated From ef8a6c958a69d39884d2940be077bfbd6d1aa491 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Sep 2026 13:09:43 +0000 Subject: [PATCH 8/8] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdf138b96b..4bc43cf9f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#3320](https://github.com/Pycord-Development/pycord/pull/3320)) - 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)) +- Fixed `AttributeError` when fetching a message from a `PartialMessageable` object that + has a thread. ([#3309](https://github.com/Pycord-Development/pycord/pull/3309)) ### Deprecated