Skip to content

Commit

Permalink
fix: add missing kwargs to TextChannel.create_thread and similar meth…
Browse files Browse the repository at this point in the history
…ods (Pycord-Development#2350)

* add missing create_thread kwargs

* style(pre-commit): auto fixes from pre-commit.com hooks

* fix and changelog

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and OmLanke committed Feb 9, 2024
1 parent 4f9f0d5 commit e8de840
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2273](https://github.com/Pycord-Development/pycord/pull/2273))
- Added `AttachmentFlags` and attachment attributes `expires_at`, `issued_at` and `hm`.
([#2342](https://github.com/Pycord-Development/pycord/pull/2342))
- Added `invitable` and `slowmode_delay` to `Thread` creation methods.
([#2350](https://github.com/Pycord-Development/pycord/pull/2350))

### Changed

Expand Down
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,
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

0 comments on commit e8de840

Please sign in to comment.