diff --git a/discord/threads.py b/discord/threads.py index f9d3bb1dd..57db26a7e 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE. from __future__ import annotations from typing import Callable, Dict, Iterable, List, Optional, Union, TYPE_CHECKING +from datetime import datetime import time import asyncio @@ -143,6 +144,7 @@ class Thread(Messageable, Hashable): 'archiver_id', 'auto_archive_duration', 'archive_timestamp', + '_created_at', ) def __init__(self, *, guild: Guild, state: ConnectionState, data: ThreadPayload): @@ -189,6 +191,7 @@ class Thread(Messageable, Hashable): self.archive_timestamp = parse_time(data['archive_timestamp']) self.locked = data.get('locked', False) self.invitable = data.get('invitable', True) + self._created_at = parse_time(data.get('create_timestamp')) def _update(self, data): try: @@ -273,7 +276,7 @@ class Thread(Messageable, Hashable): if parent is None: raise ClientException('Parent channel not found') return parent.category - + @property def category_id(self) -> Optional[int]: """The category channel ID the parent channel belongs to, if applicable. @@ -294,6 +297,16 @@ class Thread(Messageable, Hashable): raise ClientException('Parent channel not found') return parent.category_id + @property + def created_at(self) -> Optional[datetime]: + """An aware timestamp of when the thread was created in UTC. + + .. note:: + + This timestamp only exists for threads created after 9 January 2022, otherwise returns ``None``. + """ + return self._created_at + def is_private(self) -> bool: """:class:`bool`: Whether the thread is a private thread. diff --git a/discord/types/threads.py b/discord/types/threads.py index 328be1310..ed2df7e29 100644 --- a/discord/types/threads.py +++ b/discord/types/threads.py @@ -42,6 +42,7 @@ class _ThreadMetadataOptional(TypedDict, total=False): archiver_id: Snowflake locked: bool invitable: bool + create_timestamp: str class ThreadMetadata(_ThreadMetadataOptional):