From e612d95754b9038bcf79af7af6ae3ee8cad44469 Mon Sep 17 00:00:00 2001 From: Puncher <65789180+Puncher1@users.noreply.github.com> Date: Thu, 16 Mar 2023 12:15:12 +0100 Subject: [PATCH] Add mfa_level parameter to Guild.edit --- discord/guild.py | 24 ++++++++++++------------ discord/http.py | 7 +++++++ discord/types/guild.py | 4 ++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 66db5358d..3d352ae75 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1863,6 +1863,7 @@ class Guild(Hashable): invites_disabled: bool = MISSING, widget_enabled: bool = MISSING, widget_channel: Optional[Snowflake] = MISSING, + mfa_level: MFALevel = MISSING, ) -> Guild: r"""|coro| @@ -1874,7 +1875,7 @@ class Guild(Hashable): The ``rules_channel`` and ``public_updates_channel`` keyword parameters were added. .. versionchanged:: 2.0 - The ``discovery_splash`` and ``community`` keyword parameters were added. + The ``discovery_splash``, ``community``, ``premium_progress_bar_enabled``, ``discoverable``, ``invites_disabled``, ``widget_enabled``, ``widget_channel``, and ``mfa_level` keyword parameters were added. .. versionchanged:: 2.0 The newly updated guild is returned. @@ -1889,15 +1890,6 @@ class Guild(Hashable): .. versionchanged:: 2.0 The ``preferred_locale`` keyword parameter now accepts an enum instead of :class:`str`. - .. versionchanged:: 2.0 - The ``premium_progress_bar_enabled`` keyword parameter was added. - - .. versionchanged:: 2.0 - The ``discoverable`` and ``invites_disabled`` keyword parameters were added. - - .. versionchanged:: 2.0 - The ``widget_enabled`` and ``widget_channel`` keyword parameters were added. - Parameters ---------- name: :class:`str` @@ -1967,6 +1959,9 @@ class Guild(Hashable): The new widget channel. ``None`` removes the widget channel. reason: Optional[:class:`str`] The reason for editing this guild. Shows up on the audit log. + mfa_level: :class:`MFALevel` + The new guild’s Multi-Factor Authentication requirement level. + Note that you must be owner of the guild to do this. Raises ------- @@ -1980,7 +1975,7 @@ class Guild(Hashable): guild and request an ownership transfer. TypeError The type passed to the ``default_notifications``, ``verification_level``, - ``explicit_content_filter``, or ``system_channel_flags`` parameter was + ``explicit_content_filter``, ``system_channel_flags``, or ``mfa_level`` parameter was of the incorrect type. Returns @@ -1989,7 +1984,6 @@ class Guild(Hashable): The newly updated guild. Note that this has the same limitations as mentioned in :meth:`Client.fetch_guild` and may not have full data. """ - # TODO: see what fields are sent no matter if they're changed or not http = self._state.http if vanity_code is not MISSING: @@ -2125,6 +2119,12 @@ class Guild(Hashable): if widget_payload: await self._state.http.edit_widget(self.id, payload=widget_payload, reason=reason) + if mfa_level is not MISSING: + if not isinstance(mfa_level, MFALevel): + raise TypeError('mfa_level must be of type MFALevel') + + await http.edit_guild_mfa_level(self.id, mfa_level=mfa_level.value) + data = await http.edit_guild(self.id, reason=reason, **fields) return Guild(data=data, state=self._state) diff --git a/discord/http.py b/discord/http.py index 410a3c723..e7572c793 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1694,6 +1694,13 @@ class HTTPClient: return self.request(Route('PATCH', '/guilds/{guild_id}', guild_id=guild_id), json=payload, reason=reason) + def edit_guild_mfa_level( + self, guild_id: Snowflake, *, mfa_level: int, reason: Optional[str] = None + ) -> Response[guild.GuildMFALevel]: + payload = {'level': mfa_level} + + return self.request(Route('POST', '/guilds/{guild_id}/mfa', guild_id=guild_id), json=payload, reason=reason) + def edit_guild_settings(self, guild_id: Snowflake, fields): # TODO: type return self.request(Route('PATCH', '/users/@me/guilds/{guild_id}/settings', guild_id=guild_id), json=fields) diff --git a/discord/types/guild.py b/discord/types/guild.py index 9d918272f..139c7743f 100644 --- a/discord/types/guild.py +++ b/discord/types/guild.py @@ -131,6 +131,10 @@ class GuildPrune(TypedDict): pruned: Optional[int] +class GuildMFALevel(TypedDict): + level: MFALevel + + class ChannelPositionUpdate(TypedDict): id: Snowflake position: Optional[int]