Skip to content

feat: add ThreadAutoArchiveDuration enum #2826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2747](https://github.com/Pycord-Development/pycord/pull/2747))
- Added `discord.Interaction.created_at`.
([#2801](https://github.com/Pycord-Development/pycord/pull/2801))
- Added `ThreadAutoArchiveDuration` enum to get thread archive duration more
efficiently. ([#2826](https://github.com/Pycord-Development/pycord/pull/2826))

### Fixed

Expand Down
8 changes: 7 additions & 1 deletion discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
InviteTarget,
SortOrder,
StagePrivacyLevel,
)
from .enums import ThreadArchiveDuration as ThreadArchiveDurationEnum
from .enums import (
VideoQualityMode,
VoiceRegion,
try_enum,
Expand Down Expand Up @@ -1084,7 +1087,9 @@ async def edit(
sync_permissions: bool = ...,
category: CategoryChannel | None = ...,
slowmode_delay: int = ...,
default_auto_archive_duration: ThreadArchiveDuration = ...,
default_auto_archive_duration: (
ThreadArchiveDuration | ThreadArchiveDurationEnum
) = ...,
default_thread_slowmode_delay: int = ...,
default_sort_order: SortOrder = ...,
default_reaction_emoji: GuildEmoji | int | str | None = ...,
Expand Down Expand Up @@ -1130,6 +1135,7 @@ async def edit(self, *, reason=None, **options):
default_auto_archive_duration: :class:`int`
The new default auto archive duration in minutes for threads created in this channel.
Must be one of ``60``, ``1440``, ``4320``, or ``10080``.
:class:`ThreadAutoArchiveDuration` can be used alternatively.
default_thread_slowmode_delay: :class:`int`
The new default slowmode delay in seconds for threads created in this channel.

Expand Down
11 changes: 11 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from __future__ import annotations

from enum import IntEnum
import types
from collections import namedtuple
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, Union
Expand Down Expand Up @@ -78,6 +79,7 @@
"InteractionContextType",
"PollLayoutType",
"MessageReferenceType",
"ThreadArchiveDuration",
)


Expand Down Expand Up @@ -1078,6 +1080,15 @@ class SubscriptionStatus(Enum):
inactive = 2


class ThreadArchiveDuration(IntEnum):
"""Time set before the thread is auto archived"""

one_hour = 60
one_day = 1440
three_days = 4320
one_week = 10080


T = TypeVar("T")


Expand Down
9 changes: 7 additions & 2 deletions discord/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
from typing import TYPE_CHECKING, Callable, Iterable

from .abc import Messageable, _purge_messages_helper
from .enums import ChannelType, try_enum
from .enums import ChannelType
from .enums import ThreadArchiveDuration as ThreadArchiveDurationEnum
from .enums import try_enum
from .errors import ClientException
from .flags import ChannelFlags
from .mixins import Hashable
Expand Down Expand Up @@ -602,7 +604,9 @@ async def edit(
locked: bool = MISSING,
invitable: bool = MISSING,
slowmode_delay: int = MISSING,
auto_archive_duration: ThreadArchiveDuration = MISSING,
auto_archive_duration: (
ThreadArchiveDurationEnum | ThreadArchiveDuration
) = MISSING,
pinned: bool = MISSING,
applied_tags: list[ForumTag] = MISSING,
reason: str | None = None,
Expand Down Expand Up @@ -632,6 +636,7 @@ async def edit(
auto_archive_duration: :class:`int`
The new duration in minutes before a thread is automatically archived for inactivity.
Must be one of ``60``, ``1440``, ``4320``, or ``10080``.
:class:`ThreadAutoArchiveDuration` can be used alternatively.
slowmode_delay: :class:`int`
Specifies the slowmode rate limit for user in this thread, in seconds.
A value of ``0`` disables slowmode. The maximum value possible is ``21600``.
Expand Down
23 changes: 23 additions & 0 deletions docs/api/enums.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2519,3 +2519,26 @@ of :class:`enum.Enum`.
.. attribute:: inactive

The subscription is inactive and the subscription owner is not being charged.


.. class:: ThreadArchiveDuration

Represents times before a thread is archived.

.. versionadded:: 2.7

.. attribute:: one_hour

Indicates that the thread will be archived after 1 hour of inactivity.

.. attribute:: one_day

Indicates that the thread will be archived after 1 day of inactivity.

.. attribute:: three_days

Indicates that the thread will be archived after 3 days of inactivity.

.. attribute:: one_week

Indicates that the thread will be archived after 1 week of inactivity.