From e15415413b24afb13fbb67e4a0c58a35a8ee2a84 Mon Sep 17 00:00:00 2001 From: Stocker <44980366+StockerMC@users.noreply.github.com> Date: Sun, 6 Mar 2022 23:00:50 -0500 Subject: [PATCH] Add missing parameters to certain methods - slowmode_delay and reason in Message.create_thread - slowmode_delay in TextChannel.create_thread - reason in Guild.edit_widget --- discord/channel.py | 7 +++++++ discord/guild.py | 12 ++++++++++-- discord/http.py | 8 ++++++-- discord/message.py | 17 ++++++++++++++++- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index e28e03f5c..e4eb7e859 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -713,6 +713,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): type: Optional[ChannelType] = None, reason: Optional[str] = None, invitable: bool = True, + slowmode_delay: Optional[int] = None, ) -> Thread: """|coro| @@ -743,6 +744,10 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): invitable: :class:`bool` Whether non-modertators can add users to the thread. Only applicable to private threads. Defaults to ``True``. + slowmode_delay: Optional[:class:`int`] + Specifies the slowmode rate limit for user in this channel, in seconds. + The maximum value possible is `21600`. By default no slowmode rate limit + if this is ``None``. Raises ------- @@ -768,6 +773,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): type=type.value, reason=reason, invitable=invitable, + rate_limit_per_user=slowmode_delay, ) else: data = await self._state.http.start_thread_with_message( @@ -776,6 +782,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): name=name, auto_archive_duration=auto_archive_duration or self.default_auto_archive_duration, reason=reason, + rate_limit_per_user=slowmode_delay, ) return Thread(guild=self.guild, state=self._state, data=data) diff --git a/discord/guild.py b/discord/guild.py index dce1c10f0..7f4d06045 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3335,7 +3335,13 @@ class Guild(Hashable): return Widget(state=self._state, data=data) - async def edit_widget(self, *, enabled: bool = MISSING, channel: Optional[Snowflake] = MISSING) -> None: + async def edit_widget( + self, + *, + enabled: bool = MISSING, + channel: Optional[Snowflake] = MISSING, + reason: Optional[str] = None, + ) -> None: """|coro| Edits the widget of the guild. @@ -3351,6 +3357,8 @@ class Guild(Hashable): Whether to enable the widget for the guild. channel: Optional[:class:`~discord.abc.Snowflake`] The new widget channel. ``None`` removes the widget channel. + reason: Optional[:class:`str`] + The reason for editing this widget. Shows up on the audit log. Raises ------- @@ -3365,7 +3373,7 @@ class Guild(Hashable): if enabled is not MISSING: payload['enabled'] = enabled - await self._state.http.edit_widget(self.id, payload=payload) + await self._state.http.edit_widget(self.id, payload=payload, reason=reason) async def chunk(self, *, cache: bool = True) -> Optional[List[Member]]: """|coro| diff --git a/discord/http.py b/discord/http.py index 4144bef8b..585d67b97 100644 --- a/discord/http.py +++ b/discord/http.py @@ -923,11 +923,13 @@ class HTTPClient: *, name: str, auto_archive_duration: threads.ThreadArchiveDuration, + rate_limit_per_user: Optional[int] = None, reason: Optional[str] = None, ) -> Response[threads.Thread]: payload = { 'name': name, 'auto_archive_duration': auto_archive_duration, + 'rate_limit_per_user': rate_limit_per_user, } route = Route( @@ -943,6 +945,7 @@ class HTTPClient: auto_archive_duration: threads.ThreadArchiveDuration, type: threads.ThreadType, invitable: bool = True, + rate_limit_per_user: Optional[int] = None, reason: Optional[str] = None, ) -> Response[threads.Thread]: payload = { @@ -950,6 +953,7 @@ class HTTPClient: 'auto_archive_duration': auto_archive_duration, 'type': type, 'invitable': invitable, + 'rate_limit_per_user': rate_limit_per_user, } route = Route('POST', '/channels/{channel_id}/threads', channel_id=channel_id) @@ -1393,8 +1397,8 @@ class HTTPClient: def get_widget(self, guild_id: Snowflake) -> Response[widget.Widget]: return self.request(Route('GET', '/guilds/{guild_id}/widget.json', guild_id=guild_id)) - def edit_widget(self, guild_id: Snowflake, payload) -> Response[widget.WidgetSettings]: - return self.request(Route('PATCH', '/guilds/{guild_id}/widget', guild_id=guild_id), json=payload) + def edit_widget(self, guild_id: Snowflake, payload, reason: Optional[str] = None) -> Response[widget.WidgetSettings]: + return self.request(Route('PATCH', '/guilds/{guild_id}/widget', guild_id=guild_id), json=payload, reason=reason) # Invite management diff --git a/discord/message.py b/discord/message.py index 632a2f250..b0ac6f7d3 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1595,7 +1595,14 @@ class Message(Hashable): """ await self._state.http.clear_reactions(self.channel.id, self.id) - async def create_thread(self, *, name: str, auto_archive_duration: ThreadArchiveDuration = MISSING) -> Thread: + async def create_thread( + self, + *, + name: str, + auto_archive_duration: ThreadArchiveDuration = MISSING, + slowmode_delay: Optional[int] = None, + reason: Optional[str] = None, + ) -> Thread: """|coro| Creates a public thread from this message. @@ -1614,6 +1621,12 @@ class Message(Hashable): auto_archive_duration: :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 channel, in seconds. + The maximum value possible is `21600`. By default no slowmode rate limit + if this is ``None``. + reason: Optional[:class:`str`] + The reason for creating a new thread. Shows up on the audit log. Raises ------- @@ -1638,6 +1651,8 @@ class Message(Hashable): self.id, name=name, auto_archive_duration=auto_archive_duration or default_auto_archive_duration, + rate_limit_per_user=slowmode_delay, + reason=reason, ) return Thread(guild=self.guild, state=self._state, data=data)