Browse Source

Add mfa_level parameter to Guild.edit

pull/10109/head
Puncher 2 years ago
committed by dolfies
parent
commit
e612d95754
  1. 24
      discord/guild.py
  2. 7
      discord/http.py
  3. 4
      discord/types/guild.py

24
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 guilds 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)

7
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)

4
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]

Loading…
Cancel
Save