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 2 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
19 changes: 18 additions & 1 deletion discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
InviteTarget,
SortOrder,
StagePrivacyLevel,
ThreadAutoArchiveDuration,
VideoQualityMode,
VoiceRegion,
try_enum,
Expand Down Expand Up @@ -1084,7 +1085,9 @@ async def edit(
sync_permissions: bool = ...,
category: CategoryChannel | None = ...,
slowmode_delay: int = ...,
default_auto_archive_duration: ThreadArchiveDuration = ...,
default_auto_archive_duration: (
ThreadArchiveDuration | ThreadAutoArchiveDuration
) = ...,
default_thread_slowmode_delay: int = ...,
default_sort_order: SortOrder = ...,
default_reaction_emoji: GuildEmoji | int | str | None = ...,
Expand Down Expand Up @@ -1130,6 +1133,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``.
**ThreadAutoArchiveDuration** enum can be used for better understanding.
default_thread_slowmode_delay: :class:`int`
The new default slowmode delay in seconds for threads created in this channel.

Expand Down Expand Up @@ -1173,6 +1177,14 @@ async def edit(self, *, reason=None, **options):
options["flags"] = ChannelFlags._from_value(self.flags.value)
options["flags"].require_tag = options.pop("require_tag")

if "default_auto_archive_duration" in options:
default_auto_archive_duration = options["default_auto_archive_duration"]
options["default_auto_archive_duration"] = (
default_auto_archive_duration
if isinstance(default_auto_archive_duration, (int, float))
else default_auto_archive_duration.value
)

payload = await self._edit(options, reason=reason)
if payload is not None:
# the payload will always be the proper channel payload
Expand Down Expand Up @@ -1321,6 +1333,11 @@ async def create_thread(
raise InvalidArgument("file parameter must be File")
files = [file]

if auto_archive_duration is not None and isinstance(
auto_archive_duration, ThreadAutoArchiveDuration
):
auto_archive_duration = auto_archive_duration.value

try:
data = await state.http.start_forum_thread(
self.id,
Expand Down
10 changes: 10 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"InteractionContextType",
"PollLayoutType",
"MessageReferenceType",
"ThreadAutoArchiveDuration",
)


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


class ThreadAutoArchiveDuration(Enum):
"""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
13 changes: 10 additions & 3 deletions discord/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from typing import TYPE_CHECKING, Callable, Iterable

from .abc import Messageable, _purge_messages_helper
from .enums import ChannelType, try_enum
from .enums import ChannelType, ThreadAutoArchiveDuration, try_enum
from .errors import ClientException
from .flags import ChannelFlags
from .mixins import Hashable
Expand Down Expand Up @@ -602,7 +602,9 @@ async def edit(
locked: bool = MISSING,
invitable: bool = MISSING,
slowmode_delay: int = MISSING,
auto_archive_duration: ThreadArchiveDuration = MISSING,
auto_archive_duration: (
ThreadAutoArchiveDuration | ThreadArchiveDuration
) = MISSING,
pinned: bool = MISSING,
applied_tags: list[ForumTag] = MISSING,
reason: str | None = None,
Expand Down Expand Up @@ -632,6 +634,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``.
**ThreadAutoArchiveDuration** enum can be used for better understanding.
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 Expand Up @@ -662,7 +665,11 @@ async def edit(
if archived is not MISSING:
payload["archived"] = archived
if auto_archive_duration is not MISSING:
payload["auto_archive_duration"] = auto_archive_duration
payload["auto_archive_duration"] = (
auto_archive_duration.value
if isinstance(auto_archive_duration, ThreadAutoArchiveDuration)
else auto_archive_duration
)
if locked is not MISSING:
payload["locked"] = locked
if invitable is not MISSING:
Expand Down