Skip to content

Commit

Permalink
Add set_mfa_required method (Pycord-Development#1552)
Browse files Browse the repository at this point in the history
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
  • Loading branch information
3 people authored Aug 9, 2022
1 parent db38261 commit c7bdab2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
27 changes: 24 additions & 3 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ async def leave(self) -> None:
via :meth:`delete`.
Raises
--------
-------
HTTPException
Leaving the guild failed.
"""
Expand All @@ -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,
*,
Expand Down
7 changes: 7 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions discord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,7 @@ class _RolePositionRequired(TypedDict):

class RolePositionUpdate(_RolePositionRequired, total=False):
position: Optional[Snowflake]


class GuildMFAModify(TypedDict):
level: Literal[0, 1]

0 comments on commit c7bdab2

Please sign in to comment.