Add support for toggling discoverable and invites_disabled features

This commit is contained in:
Josh 2022-09-04 01:51:21 +10:00 committed by GitHub
parent fdebe069a6
commit df21c26195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 10 deletions

View File

@ -246,6 +246,7 @@ class Guild(Hashable):
- ``VERIFIED``: Guild is a verified server. - ``VERIFIED``: Guild is a verified server.
- ``VIP_REGIONS``: Guild can have 384kbps bitrate in voice channels. - ``VIP_REGIONS``: Guild can have 384kbps bitrate in voice channels.
- ``WELCOME_SCREEN_ENABLED``: Guild has enabled the welcome screen. - ``WELCOME_SCREEN_ENABLED``: Guild has enabled the welcome screen.
- ``INVITES_DISABLED``: Guild has disabled invites.
premium_tier: :class:`int` premium_tier: :class:`int`
The premium tier for this guild. Corresponds to "Nitro Server" in the official UI. The premium tier for this guild. Corresponds to "Nitro Server" in the official UI.
@ -1715,6 +1716,8 @@ class Guild(Hashable):
rules_channel: Optional[TextChannel] = MISSING, rules_channel: Optional[TextChannel] = MISSING,
public_updates_channel: Optional[TextChannel] = MISSING, public_updates_channel: Optional[TextChannel] = MISSING,
premium_progress_bar_enabled: bool = MISSING, premium_progress_bar_enabled: bool = MISSING,
discoverable: bool = MISSING,
invites_disabled: bool = MISSING,
) -> Guild: ) -> Guild:
r"""|coro| r"""|coro|
@ -1744,6 +1747,9 @@ class Guild(Hashable):
.. versionchanged:: 2.0 .. versionchanged:: 2.0
The ``premium_progress_bar_enabled`` keyword parameter was added. The ``premium_progress_bar_enabled`` keyword parameter was added.
.. versionchanged:: 2.1
The ``discoverable`` and ``invites_disabled`` keyword parameters were added.
Parameters Parameters
---------- ----------
name: :class:`str` name: :class:`str`
@ -1803,6 +1809,10 @@ class Guild(Hashable):
public updates channel. public updates channel.
premium_progress_bar_enabled: :class:`bool` premium_progress_bar_enabled: :class:`bool`
Whether the premium AKA server boost level progress bar should be enabled for the guild. Whether the premium AKA server boost level progress bar should be enabled for the guild.
discoverable: :class:`bool`
Whether server discovery is enabled for this guild.
invites_disabled: :class:`bool`
Whether joining via invites should be disabled for the guild.
reason: Optional[:class:`str`] reason: Optional[:class:`str`]
The reason for editing this guild. Shows up on the audit log. The reason for editing this guild. Shows up on the audit log.
@ -1923,17 +1933,34 @@ class Guild(Hashable):
fields['system_channel_flags'] = system_channel_flags.value fields['system_channel_flags'] = system_channel_flags.value
if any(feat is not MISSING for feat in (community, discoverable, invites_disabled)):
features = set(self.features)
if community is not MISSING: if community is not MISSING:
features = []
if community: if community:
if 'rules_channel_id' in fields and 'public_updates_channel_id' in fields: if 'rules_channel_id' in fields and 'public_updates_channel_id' in fields:
features.append('COMMUNITY') features.add('COMMUNITY')
else: else:
raise ValueError( raise ValueError(
'community field requires both rules_channel and public_updates_channel fields to be provided' 'community field requires both rules_channel and public_updates_channel fields to be provided'
) )
else:
features.discard('COMMUNITY')
fields['features'] = features if discoverable is not MISSING:
if discoverable:
features.add('DISCOVERABLE')
else:
features.discard('DISCOVERABLE')
if invites_disabled is not MISSING:
if invites_disabled:
features.add('INVITES_DISABLED')
else:
features.discard('INVITES_DISABLED')
fields['features'] = list(features)
if premium_progress_bar_enabled is not MISSING: if premium_progress_bar_enabled is not MISSING:
fields['premium_progress_bar_enabled'] = premium_progress_bar_enabled fields['premium_progress_bar_enabled'] = premium_progress_bar_enabled

View File

@ -77,6 +77,7 @@ GuildFeature = Literal[
'VERIFIED', 'VERIFIED',
'VIP_REGIONS', 'VIP_REGIONS',
'WELCOME_SCREEN_ENABLED', 'WELCOME_SCREEN_ENABLED',
'INVITES_DISABLED',
] ]