From 2ca1a3a9a48c3cc0da10c7ad2214370903c99970 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 | 14 ++++++++++++-- discord/http.py | 6 ++++++ discord/types/guild.py | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 454b5eeb7..a8fce7644 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1819,6 +1819,7 @@ class Guild(Hashable): invites_disabled: bool = MISSING, widget_enabled: bool = MISSING, widget_channel: Optional[Snowflake] = MISSING, + mfa_level: MFALevel = MISSING, ) -> Guild: r"""|coro| @@ -1852,7 +1853,7 @@ class Guild(Hashable): The ``discoverable`` and ``invites_disabled`` keyword parameters were added. .. versionchanged:: 2.3 - The ``widget_enabled`` and ``widget_channel`` keyword parameters were added. + The ``widget_enabled``, ``widget_channel``, and ``mfa_level`` keyword parameters were added. Parameters ---------- @@ -1923,6 +1924,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 ------- @@ -1936,7 +1940,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 @@ -2081,6 +2085,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(f'mfa_level must be of type MFALevel not {mfa_level.__class__.__name__}') + + 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 64f04912a..22336b323 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1432,6 +1432,12 @@ 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 get_template(self, code: str) -> Response[template.Template]: return self.request(Route('GET', '/guilds/templates/{code}', code=code)) diff --git a/discord/types/guild.py b/discord/types/guild.py index b6c2a1365..1ff2854aa 100644 --- a/discord/types/guild.py +++ b/discord/types/guild.py @@ -161,6 +161,10 @@ class GuildPrune(TypedDict): pruned: Optional[int] +class GuildMFALevel(TypedDict): + level: MFALevel + + class ChannelPositionUpdate(TypedDict): id: Snowflake position: Optional[int]