Skip to content
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

fix: Add missing kwargs to TextChannel.create_thread and similar methods #2350

Merged
merged 3 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,8 @@ async def create_thread(
message: Snowflake | None = None,
auto_archive_duration: ThreadArchiveDuration = MISSING,
type: ChannelType | None = None,
slowmode_delay: int | None = None,
invitable: bool | None = None,
reason: str | None = None,
) -> Thread:
"""|coro|
Expand All @@ -894,6 +896,12 @@ async def create_thread(
The type of thread to create. If a ``message`` is passed then this parameter
is ignored, as a thread created with a message is always a public thread.
By default, this creates a private thread if this is ``None``.
slowmode_delay: Optional[:class:`int`]
Specifies the slowmode rate limit for users in this thread, in seconds.
A value of ``0`` disables slowmode. The maximum value possible is ``21600``.
invitable: Optional[:class:`bool`]
Whether non-moderators can add other non-moderators to this thread.
Only available for private threads, where it defaults to True.
reason: :class:`str`
The reason for creating a new thread. Shows up on the audit log.

Expand All @@ -920,6 +928,8 @@ async def create_thread(
auto_archive_duration=auto_archive_duration
or self.default_auto_archive_duration,
type=type.value,
rate_limit_per_user=slowmode_delay or 0,
invitable=invitable or True,
reason=reason,
)
else:
Expand All @@ -929,6 +939,7 @@ async def create_thread(
name=name,
auto_archive_duration=auto_archive_duration
or self.default_auto_archive_duration,
rate_limit_per_user=slowmode_delay or 0,
reason=reason,
)

Expand Down
6 changes: 5 additions & 1 deletion discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,11 +1130,13 @@ def start_thread_with_message(
*,
name: str,
auto_archive_duration: threads.ThreadArchiveDuration,
rate_limit_per_user: int,
reason: str | None = None,
) -> Response[threads.Thread]:
payload = {
"name": name,
"auto_archive_duration": auto_archive_duration,
"rate_limit_per_user": rate_limit_per_user,
}

route = Route(
Expand All @@ -1152,13 +1154,15 @@ def start_thread_without_message(
name: str,
auto_archive_duration: threads.ThreadArchiveDuration,
type: threads.ThreadType,
invitable: bool = True,
rate_limit_per_user: int,
invitable: bool,
reason: str | None = None,
) -> Response[threads.Thread]:
payload = {
"name": name,
"auto_archive_duration": auto_archive_duration,
"type": type,
"rate_limit_per_user": rate_limit_per_user,
"invitable": invitable,
}

Expand Down
12 changes: 10 additions & 2 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,11 @@ async def clear_reactions(self) -> None:
await self._state.http.clear_reactions(self.channel.id, self.id)

async def create_thread(
self, *, name: str, auto_archive_duration: ThreadArchiveDuration = MISSING
self,
*,
name: str,
auto_archive_duration: ThreadArchiveDuration = MISSING,
slowmode_delay: int = MISSING,
) -> Thread:
"""|coro|

Expand All @@ -1747,9 +1751,12 @@ async def create_thread(
----------
name: :class:`str`
The name of the thread.
auto_archive_duration: :class:`int`
auto_archive_duration: Optional[:class:`int`]
The duration in minutes before a thread is automatically archived for inactivity.
If not provided, the channel's default auto archive duration is used.
slowmode_delay: Optional[: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``.

Returns
-------
Expand Down Expand Up @@ -1778,6 +1785,7 @@ async def create_thread(
name=name,
auto_archive_duration=auto_archive_duration
or default_auto_archive_duration,
rate_limit_per_user=slowmode_delay or 0,
)

self.thread = Thread(guild=self.guild, state=self._state, data=data)
Expand Down