From c7bdab2fcc02748345f42b254a897657978f5a7a Mon Sep 17 00:00:00 2001 From: Middledot <78228142+Middledot@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:15:55 -0400 Subject: [PATCH] Add set_mfa_required method (#1552) Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Co-authored-by: Lala Sabathil --- discord/guild.py | 27 ++++++++++++++++++++++++--- discord/http.py | 7 +++++++ discord/types/guild.py | 4 ++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index c64c912919..c21f438e2c 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1552,7 +1552,7 @@ async def leave(self) -> None: via :meth:`delete`. Raises - -------- + ------- HTTPException Leaving the guild failed. """ @@ -1565,15 +1565,36 @@ async def delete(self) -> None: guild. Raises - -------- + ------- HTTPException Deleting the guild failed. Forbidden You do not have permissions to delete the guild. """ - await self._state.http.delete_guild(self.id) + async def set_mfa_required(self, required: bool, *, reason: str = None) -> None: + """|coro| + + Set whether it is required to have MFA enabled on your account + to perform moderation actions. You must be the guild owner to do this. + + Parameters + ----------- + required: :class:`bool` + Whether MFA should be required to perform moderation actions. + reason: :class:`str` + The reason to show up in the audit log. + + Raises + ------- + HTTPException + The operation failed. + Forbidden + You are not the owner of the guild. + """ + await self._state.http.edit_guild_mfa(self.id, required, reason=reason) + async def edit( self, *, diff --git a/discord/http.py b/discord/http.py index 24ec58ce69..99590377f3 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1334,6 +1334,13 @@ def edit_guild(self, guild_id: Snowflake, *, reason: Optional[str] = None, **fie reason=reason, ) + def edit_guild_mfa(self, guild_id: Snowflake, required: bool, *, reason: Optional[str]) -> Response[guild.GuildMFAModify]: + return self.request( + Route("POST", "/guilds/{guild_id}/mfa", guild_id=guild_id), + json={"level": int(required)}, + 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 8435e9c45e..b5b39dd807 100644 --- a/discord/types/guild.py +++ b/discord/types/guild.py @@ -183,3 +183,7 @@ class _RolePositionRequired(TypedDict): class RolePositionUpdate(_RolePositionRequired, total=False): position: Optional[Snowflake] + + +class GuildMFAModify(TypedDict): + level: Literal[0, 1]