From 1e03911caa31302cc837f92de5f3cd33bc66d11c Mon Sep 17 00:00:00 2001 From: owocado <24418520+owocado@users.noreply.github.com> Date: Sat, 15 Mar 2025 12:54:13 +0000 Subject: [PATCH 1/4] add missing attributes in `AppCommandChannel` --- discord/app_commands/models.py | 51 +++++++++++++++++++++++++++++++++- discord/types/interactions.py | 12 ++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/discord/app_commands/models.py b/discord/app_commands/models.py index e8a96784b..df992af7c 100644 --- a/discord/app_commands/models.py +++ b/discord/app_commands/models.py @@ -26,7 +26,7 @@ from __future__ import annotations from datetime import datetime from .errors import MissingApplicationID -from ..flags import AppCommandContext, AppInstallationType +from ..flags import AppCommandContext, AppInstallationType, ChannelFlags from .translator import TranslationContextLocation, TranslationContext, locale_str, Translator from ..permissions import Permissions from ..enums import ( @@ -575,6 +575,23 @@ class AppCommandChannel(Hashable): the application command in that channel. guild_id: :class:`int` The guild ID this channel belongs to. + category_id: Optional[:class:`int`] + The category channel ID this channel belongs to, if applicable. + topic: Optional[:class:`str`] + The channel's topic. ``None`` if it doesn't exist. + position: :class:`int` + The position in the channel list. This is a number that starts at 0. e.g. the + top channel is position 0. + last_message_id: Optional[:class:`int`] + The last message ID of the message sent to this channel. It may + *not* point to an existing or valid message. + slowmode_delay: :class:`int` + The number of seconds a member must wait between sending messages + in this channel. A value of ``0`` denotes that it is disabled. + Bots and users with :attr:`~Permissions.manage_channels` or + :attr:`~Permissions.manage_messages` bypass slowmode. + nsfw: :class:`bool` + If the channel is marked as "not safe for work" or "age restricted". """ __slots__ = ( @@ -583,6 +600,14 @@ class AppCommandChannel(Hashable): 'name', 'permissions', 'guild_id', + 'topic', + 'nsfw', + 'position', + 'category_id', + 'slowmode_delay', + 'last_message_id', + '_last_pin', + '_flags', '_state', ) @@ -599,6 +624,14 @@ class AppCommandChannel(Hashable): self.type: ChannelType = try_enum(ChannelType, data['type']) self.name: str = data['name'] self.permissions: Permissions = Permissions(int(data['permissions'])) + self.topic: Optional[str] = data.get('topic') + self.position: int = data.get('position') or 0 + self.nsfw: bool = data.get('nsfw') or False + self.category_id: Optional[int] = _get_as_snowflake(data, 'parent_id') + self.slowmode_delay: int = data.get('rate_limit_per_user') or 0 + self.last_message_id: Optional[int] = _get_as_snowflake(data, 'last_message_id') + self._last_pin: Optional[datetime] = parse_time(data.get('last_pin_timestamp')) + self._flags: int = data.get('flags', 0) def __str__(self) -> str: return self.name @@ -611,6 +644,22 @@ class AppCommandChannel(Hashable): """Optional[:class:`~discord.Guild`]: The channel's guild, from cache, if found.""" return self._state._get_guild(self.guild_id) + @property + def flags(self) -> ChannelFlags: + """:class:`ChannelFlags`: The flags associated with this channel object. + + .. versionadded:: 2.6 + """ + return ChannelFlags._from_value(self._flags) + + def is_nsfw(self) -> bool: + """:class:`bool`: Checks if the channel is NSFW.""" + return self.nsfw + + def is_news(self) -> bool: + """:class:`bool`: Checks if the channel is a news channel.""" + return self.type == ChannelType.news + def resolve(self) -> Optional[GuildChannel]: """Resolves the application command channel to the appropriate channel from cache if found. diff --git a/discord/types/interactions.py b/discord/types/interactions.py index 3f3516c3a..310fb7950 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -27,9 +27,9 @@ from __future__ import annotations from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union from typing_extensions import NotRequired -from .channel import ChannelTypeWithoutThread, ThreadMetadata, GuildChannel, InteractionDMChannel, GroupDMChannel +from .channel import ChannelTypeWithoutThread, GuildChannel, InteractionDMChannel, GroupDMChannel from .sku import Entitlement -from .threads import ThreadType +from .threads import ThreadType, ThreadMetadata from .member import Member from .message import Attachment from .role import Role @@ -64,6 +64,14 @@ class _BasePartialChannel(TypedDict): class PartialChannel(_BasePartialChannel): type: ChannelTypeWithoutThread + topic: NotRequired[str] + position: int + nsfw: bool + flags: int + rate_limit_per_user: int + parent_id: Snowflake + last_message_id: Snowflake + last_pin_timestamp: NotRequired[str] class PartialThread(_BasePartialChannel): From ad25c05a840dc9d650e747eb798446fd25556aba Mon Sep 17 00:00:00 2001 From: owocado <24418520+owocado@users.noreply.github.com> Date: Wed, 30 Apr 2025 17:26:35 +0530 Subject: [PATCH 2/4] fix types --- discord/types/interactions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/types/interactions.py b/discord/types/interactions.py index 310fb7950..5dc62ce70 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -69,8 +69,8 @@ class PartialChannel(_BasePartialChannel): nsfw: bool flags: int rate_limit_per_user: int - parent_id: Snowflake - last_message_id: Snowflake + parent_id: Optional[Snowflake] + last_message_id: Optional[Snowflake] last_pin_timestamp: NotRequired[str] From 661811194f2e68f3f3f8eaa6d6d3b1a3f1465a93 Mon Sep 17 00:00:00 2001 From: owocado <24418520+owocado@users.noreply.github.com> Date: Wed, 30 Apr 2025 13:06:57 +0100 Subject: [PATCH 3/4] fix CI --- discord/app_commands/models.py | 4 ++-- discord/types/interactions.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/app_commands/models.py b/discord/app_commands/models.py index df992af7c..1d878ffdf 100644 --- a/discord/app_commands/models.py +++ b/discord/app_commands/models.py @@ -588,8 +588,8 @@ class AppCommandChannel(Hashable): slowmode_delay: :class:`int` The number of seconds a member must wait between sending messages in this channel. A value of ``0`` denotes that it is disabled. - Bots and users with :attr:`~Permissions.manage_channels` or - :attr:`~Permissions.manage_messages` bypass slowmode. + Bots and users with :attr:`~discord.Permissions.manage_channels` or + :attr:`~discord.Permissions.manage_messages` bypass slowmode. nsfw: :class:`bool` If the channel is marked as "not safe for work" or "age restricted". """ diff --git a/discord/types/interactions.py b/discord/types/interactions.py index 5dc62ce70..a0434931f 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE. from __future__ import annotations -from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union +from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union, Optional from typing_extensions import NotRequired from .channel import ChannelTypeWithoutThread, GuildChannel, InteractionDMChannel, GroupDMChannel From d44b3cf05e954135d3ed73564a7903c4e58af513 Mon Sep 17 00:00:00 2001 From: owocado <24418520+owocado@users.noreply.github.com> Date: Wed, 30 Apr 2025 13:12:10 +0100 Subject: [PATCH 4/4] fix CI --- discord/app_commands/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/app_commands/models.py b/discord/app_commands/models.py index 1d878ffdf..ccc4a61aa 100644 --- a/discord/app_commands/models.py +++ b/discord/app_commands/models.py @@ -646,7 +646,7 @@ class AppCommandChannel(Hashable): @property def flags(self) -> ChannelFlags: - """:class:`ChannelFlags`: The flags associated with this channel object. + """:class:`~discord.ChannelFlags`: The flags associated with this channel object. .. versionadded:: 2.6 """