Skip to content

Commit a62b25c

Browse files
authored
Add missing attributes in AppCommandChannel
1 parent e9f807e commit a62b25c

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

discord/app_commands/models.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from datetime import datetime
2727

2828
from .errors import MissingApplicationID
29-
from ..flags import AppCommandContext, AppInstallationType
29+
from ..flags import AppCommandContext, AppInstallationType, ChannelFlags
3030
from .translator import TranslationContextLocation, TranslationContext, locale_str, Translator
3131
from ..permissions import Permissions
3232
from ..enums import (
@@ -575,6 +575,35 @@ class AppCommandChannel(Hashable):
575575
the application command in that channel.
576576
guild_id: :class:`int`
577577
The guild ID this channel belongs to.
578+
category_id: Optional[:class:`int`]
579+
The category channel ID this channel belongs to, if applicable.
580+
581+
.. versionadded:: 2.6
582+
topic: Optional[:class:`str`]
583+
The channel's topic. ``None`` if it doesn't exist.
584+
585+
.. versionadded:: 2.6
586+
position: :class:`int`
587+
The position in the channel list. This is a number that starts at 0. e.g. the
588+
top channel is position 0.
589+
590+
.. versionadded:: 2.6
591+
last_message_id: Optional[:class:`int`]
592+
The last message ID of the message sent to this channel. It may
593+
*not* point to an existing or valid message.
594+
595+
.. versionadded:: 2.6
596+
slowmode_delay: :class:`int`
597+
The number of seconds a member must wait between sending messages
598+
in this channel. A value of ``0`` denotes that it is disabled.
599+
Bots and users with :attr:`~discord.Permissions.manage_channels` or
600+
:attr:`~discord.Permissions.manage_messages` bypass slowmode.
601+
602+
.. versionadded:: 2.6
603+
nsfw: :class:`bool`
604+
If the channel is marked as "not safe for work" or "age restricted".
605+
606+
.. versionadded:: 2.6
578607
"""
579608

580609
__slots__ = (
@@ -583,6 +612,14 @@ class AppCommandChannel(Hashable):
583612
'name',
584613
'permissions',
585614
'guild_id',
615+
'topic',
616+
'nsfw',
617+
'position',
618+
'category_id',
619+
'slowmode_delay',
620+
'last_message_id',
621+
'_last_pin',
622+
'_flags',
586623
'_state',
587624
)
588625

@@ -599,6 +636,14 @@ def __init__(
599636
self.type: ChannelType = try_enum(ChannelType, data['type'])
600637
self.name: str = data['name']
601638
self.permissions: Permissions = Permissions(int(data['permissions']))
639+
self.topic: Optional[str] = data.get('topic')
640+
self.position: int = data.get('position') or 0
641+
self.nsfw: bool = data.get('nsfw') or False
642+
self.category_id: Optional[int] = _get_as_snowflake(data, 'parent_id')
643+
self.slowmode_delay: int = data.get('rate_limit_per_user') or 0
644+
self.last_message_id: Optional[int] = _get_as_snowflake(data, 'last_message_id')
645+
self._last_pin: Optional[datetime] = parse_time(data.get('last_pin_timestamp'))
646+
self._flags: int = data.get('flags', 0)
602647

603648
def __str__(self) -> str:
604649
return self.name
@@ -611,6 +656,28 @@ def guild(self) -> Optional[Guild]:
611656
"""Optional[:class:`~discord.Guild`]: The channel's guild, from cache, if found."""
612657
return self._state._get_guild(self.guild_id)
613658

659+
@property
660+
def flags(self) -> ChannelFlags:
661+
""":class:`~discord.ChannelFlags`: The flags associated with this channel object.
662+
663+
.. versionadded:: 2.6
664+
"""
665+
return ChannelFlags._from_value(self._flags)
666+
667+
def is_nsfw(self) -> bool:
668+
""":class:`bool`: Checks if the channel is NSFW.
669+
670+
.. versionadded:: 2.6
671+
"""
672+
return self.nsfw
673+
674+
def is_news(self) -> bool:
675+
""":class:`bool`: Checks if the channel is a news channel.
676+
677+
.. versionadded:: 2.6
678+
"""
679+
return self.type == ChannelType.news
680+
614681
def resolve(self) -> Optional[GuildChannel]:
615682
"""Resolves the application command channel to the appropriate channel
616683
from cache if found.

discord/types/interactions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
from __future__ import annotations
2626

27-
from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union
27+
from typing import TYPE_CHECKING, Dict, List, Literal, TypedDict, Union, Optional
2828
from typing_extensions import NotRequired
2929

30-
from .channel import ChannelTypeWithoutThread, ThreadMetadata, GuildChannel, InteractionDMChannel, GroupDMChannel
30+
from .channel import ChannelTypeWithoutThread, GuildChannel, InteractionDMChannel, GroupDMChannel
3131
from .sku import Entitlement
32-
from .threads import ThreadType
32+
from .threads import ThreadType, ThreadMetadata
3333
from .member import Member
3434
from .message import Attachment
3535
from .role import Role
@@ -64,6 +64,14 @@ class _BasePartialChannel(TypedDict):
6464

6565
class PartialChannel(_BasePartialChannel):
6666
type: ChannelTypeWithoutThread
67+
topic: NotRequired[str]
68+
position: int
69+
nsfw: bool
70+
flags: int
71+
rate_limit_per_user: int
72+
parent_id: Optional[Snowflake]
73+
last_message_id: Optional[Snowflake]
74+
last_pin_timestamp: NotRequired[str]
6775

6876

6977
class PartialThread(_BasePartialChannel):

0 commit comments

Comments
 (0)