Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set_mfa_required method #1552

Merged
merged 4 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, toggle: bool, *, reason: str = 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
-----------
toggle: :class:`bool`
Whether it should be required.
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, toggle, 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, toggle: bool, *, reason: Optional[str]) -> Response[guild.GuildMFAModify]:
return self.request(
Route("POST", "/guilds/{guild_id}/mfa", guild_id=guild_id),
json={"level": int(toggle)},
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]