Skip to content

Commit db42eba

Browse files
authored
Add more attributes to AppCommandChannel/Thread
1 parent 7b3f798 commit db42eba

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

discord/app_commands/models.py

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
Locale,
3838
try_enum,
3939
)
40+
import array
4041
from ..mixins import Hashable
4142
from ..utils import _get_as_snowflake, parse_time, snowflake_time, MISSING
4243
from ..object import Object
@@ -84,7 +85,7 @@ def is_app_command_argument_type(value: int) -> bool:
8485
from ..abc import Snowflake
8586
from ..state import ConnectionState
8687
from ..guild import GuildChannel, Guild
87-
from ..channel import TextChannel
88+
from ..channel import TextChannel, ForumChannel, ForumTag
8889
from ..threads import Thread
8990
from ..user import User
9091

@@ -719,6 +720,14 @@ def mention(self) -> str:
719720
""":class:`str`: The string that allows you to mention the channel."""
720721
return f'<#{self.id}>'
721722

723+
@property
724+
def jump_url(self) -> str:
725+
""":class:`str`: Returns a URL that allows the client to jump to the channel.
726+
727+
.. versionadded:: 2.6
728+
"""
729+
return f'https://discord.com/channels/{self.guild_id}/{self.id}'
730+
722731
@property
723732
def created_at(self) -> datetime:
724733
""":class:`datetime.datetime`: An aware timestamp of when this channel was created in UTC."""
@@ -758,6 +767,30 @@ class AppCommandThread(Hashable):
758767
The name of the thread.
759768
parent_id: :class:`int`
760769
The parent text channel ID this thread belongs to.
770+
owner_id: :class:`int`
771+
The user's ID that created this thread.
772+
773+
.. versionadded:: 2.6
774+
last_message_id: Optional[:class:`int`]
775+
The last message ID of the message sent to this thread. It may
776+
*not* point to an existing or valid message.
777+
778+
.. versionadded:: 2.6
779+
slowmode_delay: :class:`int`
780+
The number of seconds a member must wait between sending messages
781+
in this thread. A value of ``0`` denotes that it is disabled.
782+
Bots and users with :attr:`~discord.Permissions.manage_channels` or
783+
:attr:`~discord.Permissions.manage_messages` bypass slowmode.
784+
785+
.. versionadded:: 2.6
786+
message_count: :class:`int`
787+
An approximate number of messages in this thread.
788+
789+
.. versionadded:: 2.6
790+
member_count: :class:`int`
791+
An approximate number of members in this thread. This caps at 50.
792+
793+
.. versionadded:: 2.6
761794
permissions: :class:`~discord.Permissions`
762795
The resolved permissions of the user who invoked
763796
the application command in that thread.
@@ -792,6 +825,13 @@ class AppCommandThread(Hashable):
792825
'archive_timestamp',
793826
'locked',
794827
'invitable',
828+
'owner_id',
829+
'message_count',
830+
'member_count',
831+
'slowmode_delay',
832+
'last_message_id',
833+
'_applied_tags',
834+
'_flags',
795835
'_created_at',
796836
'_state',
797837
)
@@ -810,6 +850,13 @@ def __init__(
810850
self.type: ChannelType = try_enum(ChannelType, data['type'])
811851
self.name: str = data['name']
812852
self.permissions: Permissions = Permissions(int(data['permissions']))
853+
self.owner_id: int = int(data['owner_id'])
854+
self.member_count: int = int(data['member_count'])
855+
self.message_count: int = int(data['message_count'])
856+
self.last_message_id: Optional[int] = _get_as_snowflake(data, 'last_message_id')
857+
self.slowmode_delay: int = data.get('rate_limit_per_user', 0)
858+
self._applied_tags: array.array[int] = array.array('Q', map(int, data.get('applied_tags', [])))
859+
self._flags: int = data.get('flags', 0)
813860
self._unroll_metadata(data['thread_metadata'])
814861

815862
def __str__(self) -> str:
@@ -833,15 +880,58 @@ def _unroll_metadata(self, data: ThreadMetadata) -> None:
833880
self._created_at: Optional[datetime] = parse_time(data.get('create_timestamp'))
834881

835882
@property
836-
def parent(self) -> Optional[TextChannel]:
837-
"""Optional[:class:`~discord.TextChannel`]: The parent channel this thread belongs to."""
883+
def applied_tags(self) -> List[ForumTag]:
884+
"""List[:class:`~discord.ForumTag`]: A list of tags applied to this thread.
885+
886+
.. versionadded:: 2.6
887+
"""
888+
tags = []
889+
if self.parent is None or self.parent.type not in (ChannelType.forum, ChannelType.media):
890+
return tags
891+
892+
parent = self.parent
893+
for tag_id in self._applied_tags:
894+
tag = parent.get_tag(tag_id) # type: ignore # parent here will be ForumChannel instance
895+
if tag is not None:
896+
tags.append(tag)
897+
898+
return tags
899+
900+
@property
901+
def parent(self) -> Optional[Union[ForumChannel, TextChannel]]:
902+
"""Optional[Union[:class:`~discord.ForumChannel`, :class:`~discord.TextChannel`]]: The parent channel
903+
this thread belongs to."""
838904
return self.guild.get_channel(self.parent_id) # type: ignore
839905

906+
@property
907+
def flags(self) -> ChannelFlags:
908+
""":class:`~discord.ChannelFlags`: The flags associated with this thread.
909+
910+
.. versionadded:: 2.6
911+
"""
912+
return ChannelFlags._from_value(self._flags)
913+
914+
@property
915+
def owner(self) -> Optional[Member]:
916+
"""Optional[:class:`~discord.Member`]: The member this thread belongs to.
917+
918+
.. versionadded:: 2.6
919+
"""
920+
return self.guild.get_member(self.owner_id) # type: ignore
921+
840922
@property
841923
def mention(self) -> str:
842924
""":class:`str`: The string that allows you to mention the thread."""
843925
return f'<#{self.id}>'
844926

927+
@property
928+
def jump_url(self) -> str:
929+
""":class:`str`: Returns a URL that allows the client to jump to the thread.
930+
931+
.. versionadded:: 2.6
932+
"""
933+
return f'https://discord.com/channels/{self.guild_id}/{self.id}'
934+
845935
@property
846936
def created_at(self) -> Optional[datetime]:
847937
"""An aware timestamp of when the thread was created in UTC.

discord/types/interactions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ class PartialThread(_BasePartialChannel):
7878
type: ThreadType
7979
thread_metadata: ThreadMetadata
8080
parent_id: Snowflake
81+
applied_tags: NotRequired[List[Snowflake]]
82+
owner_id: Snowflake
83+
message_count: int
84+
member_count: int
85+
rate_limit_per_user: int
86+
last_message_id: NotRequired[Optional[Snowflake]]
87+
flags: NotRequired[int]
8188

8289

8390
class ResolvedData(TypedDict, total=False):

0 commit comments

Comments
 (0)