Skip to content

Commit 3679443

Browse files
committed
feat: add ThreadAutoArchiveDuration enum
Add an enumeration ThreadAutoArchiveDuration to get time before the thread was archived. The selected enumeration value is automatically retrieved. You can always set the archiving time as a number without using this enumeration.
1 parent 1c65fc8 commit 3679443

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ These changes are available on the `master` branch, but have not yet been releas
5757
([#2747](https://github.com/Pycord-Development/pycord/pull/2747))
5858
- Added `discord.Interaction.created_at`.
5959
([#2801](https://github.com/Pycord-Development/pycord/pull/2801))
60+
- Added `ThreadAutoArchiveDuration` enum to get thread archive duration more efficiently.
61+
([#2826](https://github.com/Pycord-Development/pycord/pull/2826))
6062

6163
### Fixed
6264

discord/channel.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
StagePrivacyLevel,
4242
VideoQualityMode,
4343
VoiceRegion,
44+
ThreadAutoArchiveDuration,
4445
try_enum,
4546
)
4647
from .errors import ClientException, InvalidArgument
@@ -1084,7 +1085,7 @@ async def edit(
10841085
sync_permissions: bool = ...,
10851086
category: CategoryChannel | None = ...,
10861087
slowmode_delay: int = ...,
1087-
default_auto_archive_duration: ThreadArchiveDuration = ...,
1088+
default_auto_archive_duration: ThreadArchiveDuration | ThreadAutoArchiveDuration = ...,
10881089
default_thread_slowmode_delay: int = ...,
10891090
default_sort_order: SortOrder = ...,
10901091
default_reaction_emoji: GuildEmoji | int | str | None = ...,
@@ -1130,6 +1131,7 @@ async def edit(self, *, reason=None, **options):
11301131
default_auto_archive_duration: :class:`int`
11311132
The new default auto archive duration in minutes for threads created in this channel.
11321133
Must be one of ``60``, ``1440``, ``4320``, or ``10080``.
1134+
**ThreadAutoArchiveDuration** enum can be used for better understanding.
11331135
default_thread_slowmode_delay: :class:`int`
11341136
The new default slowmode delay in seconds for threads created in this channel.
11351137
@@ -1173,6 +1175,12 @@ async def edit(self, *, reason=None, **options):
11731175
options["flags"] = ChannelFlags._from_value(self.flags.value)
11741176
options["flags"].require_tag = options.pop("require_tag")
11751177

1178+
if "default_auto_archive_duration" in options:
1179+
default_auto_archive_duration = options["default_auto_archive_duration"]
1180+
options["default_auto_archive_duration"] = default_auto_archive_duration \
1181+
if isinstance(default_auto_archive_duration, (int, float)) \
1182+
else default_auto_archive_duration.value
1183+
11761184
payload = await self._edit(options, reason=reason)
11771185
if payload is not None:
11781186
# the payload will always be the proper channel payload
@@ -1321,6 +1329,9 @@ async def create_thread(
13211329
raise InvalidArgument("file parameter must be File")
13221330
files = [file]
13231331

1332+
if auto_archive_duration is not None and isinstance(auto_archive_duration, ThreadAutoArchiveDuration):
1333+
auto_archive_duration = auto_archive_duration.value
1334+
13241335
try:
13251336
data = await state.http.start_forum_thread(
13261337
self.id,

discord/enums.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"InteractionContextType",
7979
"PollLayoutType",
8080
"MessageReferenceType",
81+
"ThreadAutoArchiveDuration"
8182
)
8283

8384

@@ -1078,6 +1079,15 @@ class SubscriptionStatus(Enum):
10781079
inactive = 2
10791080

10801081

1082+
class ThreadAutoArchiveDuration(Enum):
1083+
"""Time set before the thread is auto archived"""
1084+
1085+
one_hour = 60
1086+
one_day = 1440
1087+
three_days = 4320
1088+
one_week = 10080
1089+
1090+
10811091
T = TypeVar("T")
10821092

10831093

discord/threads.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from typing import TYPE_CHECKING, Callable, Iterable
2929

3030
from .abc import Messageable, _purge_messages_helper
31-
from .enums import ChannelType, try_enum
31+
from .enums import ChannelType, try_enum, ThreadAutoArchiveDuration
3232
from .errors import ClientException
3333
from .flags import ChannelFlags
3434
from .mixins import Hashable
@@ -602,7 +602,7 @@ async def edit(
602602
locked: bool = MISSING,
603603
invitable: bool = MISSING,
604604
slowmode_delay: int = MISSING,
605-
auto_archive_duration: ThreadArchiveDuration = MISSING,
605+
auto_archive_duration: ThreadAutoArchiveDuration | ThreadArchiveDuration = MISSING,
606606
pinned: bool = MISSING,
607607
applied_tags: list[ForumTag] = MISSING,
608608
reason: str | None = None,
@@ -632,6 +632,7 @@ async def edit(
632632
auto_archive_duration: :class:`int`
633633
The new duration in minutes before a thread is automatically archived for inactivity.
634634
Must be one of ``60``, ``1440``, ``4320``, or ``10080``.
635+
**ThreadAutoArchiveDuration** enum can be used for better understanding.
635636
slowmode_delay: :class:`int`
636637
Specifies the slowmode rate limit for user in this thread, in seconds.
637638
A value of ``0`` disables slowmode. The maximum value possible is ``21600``.
@@ -662,7 +663,9 @@ async def edit(
662663
if archived is not MISSING:
663664
payload["archived"] = archived
664665
if auto_archive_duration is not MISSING:
665-
payload["auto_archive_duration"] = auto_archive_duration
666+
payload["auto_archive_duration"] = auto_archive_duration.value \
667+
if isinstance(auto_archive_duration, ThreadAutoArchiveDuration) \
668+
else auto_archive_duration
666669
if locked is not MISSING:
667670
payload["locked"] = locked
668671
if invitable is not MISSING:

0 commit comments

Comments
 (0)