From 63974ec46dae497bf7fafbf7b592ef6562ee0f14 Mon Sep 17 00:00:00 2001 From: Nadir Chowdhury Date: Wed, 5 May 2021 12:30:54 +0100 Subject: [PATCH] Add discovery_splash and community field to Guild.edit --- discord/guild.py | 80 ++++++++++++++++++++++++++++++++++++++++++++---- discord/http.py | 2 ++ 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index dac1c6fa5..6c0b0901f 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE. import copy from collections import namedtuple -from typing import List, TYPE_CHECKING +from typing import List, Optional, TYPE_CHECKING, overload from . import utils, abc from .role import Role @@ -991,8 +991,39 @@ class Guild(Hashable): await self._state.http.delete_guild(self.id) + @overload + async def edit( + self, + *, + reason: Optional[str] = ..., + name: str = ..., + description: Optional[str] = ..., + icon: Optional[bytes] = ..., + banner: Optional[bytes] = ..., + splash: Optional[bytes] = ..., + discovery_splash: Optional[bytes] = ..., + community: bool = ..., + region: Optional[VoiceRegion] = ..., + afk_channel: Optional[VoiceChannel] = ..., + afk_timeout: int = ..., + default_notifications: NotificationLevel = ..., + verification_level: VerificationLevel = ..., + explicit_content_filter: ContentFilter = ..., + vanity_code: str = ..., + system_channel: Optional[TextChannel] = ..., + system_channel_flags: SystemChannelFlags = ..., + preferred_locale: str = ..., + rules_channel: Optional[TextChannel] = ..., + public_updates_channel: Optional[TextChannel] = ..., + ) -> None: + ... + + @overload + async def edit(self) -> None: + ... + async def edit(self, *, reason=None, **fields): - """|coro| + r"""|coro| Edits the guild. @@ -1002,25 +1033,37 @@ class Guild(Hashable): .. versionchanged:: 1.4 The `rules_channel` and `public_updates_channel` keyword-only parameters were added. + .. versionchanged:: 2.0 + The `discovery_splash` and `community` keyword-only parameters were added. + Parameters ---------- name: :class:`str` The new name of the guild. - description: :class:`str` - The new description of the guild. This is only available to guilds that - contain ``PUBLIC`` in :attr:`Guild.features`. + description: Optional[:class:`str`] + The new description of the guild. Could be ``None`` for no description. + This is only available to guilds that contain ``PUBLIC`` in :attr:`Guild.features`. icon: :class:`bytes` A :term:`py:bytes-like object` representing the icon. Only PNG/JPEG is supported. GIF is only available to guilds that contain ``ANIMATED_ICON`` in :attr:`Guild.features`. Could be ``None`` to denote removal of the icon. banner: :class:`bytes` A :term:`py:bytes-like object` representing the banner. - Could be ``None`` to denote removal of the banner. + Could be ``None`` to denote removal of the banner. This is only available to guilds that contain + ``BANNER`` in :attr:`Guild.features`. splash: :class:`bytes` A :term:`py:bytes-like object` representing the invite splash. Only PNG/JPEG supported. Could be ``None`` to denote removing the splash. This is only available to guilds that contain ``INVITE_SPLASH`` in :attr:`Guild.features`. + discovery_splash: :class:`bytes` + A :term:`py:bytes-like object` representing the discovery splash. + Only PNG/JPEG supported. Could be ``None`` to denote removing the + splash. This is only available to guilds that contain ``DISCOVERABLE`` + in :attr:`Guild.features`. + community: :class:`bool` + Whether the guild should be a Community guild. If set to ``True``\, both ``rules_channel`` + and ``public_updates_channel`` parameters are required. region: :class:`VoiceRegion` The new region for the guild's voice communication. afk_channel: Optional[:class:`VoiceChannel`] @@ -1106,6 +1149,16 @@ class Guild(Hashable): else: splash = None + try: + discovery_splash_bytes = fields['discovery_splash'] + except KeyError: + pass + else: + if discovery_splash_bytes is not None: + fields['discovery_splash'] = utils._bytes_to_base64_data(discovery_splash_bytes) + else: + fields['discovery_splash'] = None + fields['icon'] = icon fields['banner'] = banner fields['splash'] = splash @@ -1181,6 +1234,21 @@ class Guild(Hashable): fields['public_updates_channel_id'] = public_updates_channel else: fields['public_updates_channel_id'] = public_updates_channel.id + + try: + community = fields.pop('community') + except KeyError: + pass + else: + features = [] + if community: + if 'rules_channel_id' in fields and 'public_updates_channel_id' in fields: + features.append('COMMUNITY') + else: + raise InvalidArgument('community field requires both rules_channel and public_updates_channel fields to be provided') + + fields['features'] = features + await http.edit_guild(self.id, reason=reason, **fields) async def fetch_channels(self): diff --git a/discord/http.py b/discord/http.py index 0eb481245..dcd6131e2 100644 --- a/discord/http.py +++ b/discord/http.py @@ -785,6 +785,8 @@ class HTTPClient: 'owner_id', 'afk_channel_id', 'splash', + 'discovery_splash', + 'features', 'verification_level', 'system_channel_id', 'default_message_notifications',