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

feat: support INVITES_DISABLED guild feature #718

Merged
merged 10 commits into from
Sep 7, 2022
1 change: 1 addition & 0 deletions changelog/718.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for modifying the ``INVITES_DISABLED`` guild feature using :func:`Guild.edit`.
32 changes: 29 additions & 3 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class Guild(Hashable):
- ``HAS_DIRECTORY_ENTRY``: Guild is listed in a student hub.
- ``HUB``: Guild is a student hub.
- ``INVITE_SPLASH``: Guild's invite page can have a special splash.
- ``INVITES_DISABLED``: Guild has paused invites, preventing new users from joining.
- ``LINKED_TO_HUB``: Guild is linked to a student hub.
- ``MEMBER_VERIFICATION_GATE_ENABLED``: Guild has Membership Screening enabled.
- ``MONETIZATION_ENABLED``: Guild has enabled monetization.
Expand Down Expand Up @@ -1746,6 +1747,7 @@ async def edit(
splash: Optional[AssetBytes] = MISSING,
discovery_splash: Optional[AssetBytes] = MISSING,
community: bool = MISSING,
invites_disabled: bool = MISSING,
afk_channel: Optional[VoiceChannel] = MISSING,
owner: Snowflake = MISSING,
afk_timeout: int = MISSING,
Expand Down Expand Up @@ -1829,6 +1831,16 @@ async def edit(
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.
invites_disabled: :class:`bool`
Whether the guild has paused invites, preventing new users from joining.

This is only available to guilds that contain ``COMMUNITY``
in :attr:`Guild.features`.

This cannot be changed at the same time as the ``community`` feature due a Discord API limitation.

.. versionadded:: 2.6

afk_channel: Optional[:class:`VoiceChannel`]
The new channel that is the AFK channel. Could be ``None`` for no AFK channel.
afk_timeout: :class:`int`
Expand Down Expand Up @@ -1883,7 +1895,8 @@ async def edit(
ValueError
``community`` was set without setting both ``rules_channel`` and ``public_updates_channel`` parameters,
or if you are not the owner of the guild and request an ownership transfer,
or the image format passed in to ``icon`` is invalid.
or the image format passed in to ``icon`` is invalid,
or both ``community`` and ``invites_disabled`` were provided.

Returns
-------
Expand Down Expand Up @@ -1974,7 +1987,7 @@ async def edit(

fields["system_channel_flags"] = system_channel_flags.value

if community is not MISSING:
if community is not MISSING or invites_disabled is not MISSING:
# If we don't have complete feature information for the guild,
# it is possible to disable or enable other features that we didn't intend to touch.
# To enable or disable a feature, we will need to provide all of the existing features in advance.
Expand All @@ -1985,7 +1998,7 @@ async def edit(
features = set(self.features)
if community is not MISSING:
if not isinstance(community, bool):
raise TypeError("community must be a bool instance")
raise TypeError("community must be a bool")
if community:
if "rules_channel_id" in fields and "public_updates_channel_id" in fields:
features.add("COMMUNITY")
Expand All @@ -1996,6 +2009,19 @@ async def edit(
else:
features.discard("COMMUNITY")

if invites_disabled is not MISSING:
if community is not MISSING:
raise ValueError(
shiftinv marked this conversation as resolved.
Show resolved Hide resolved
"cannot modify both the COMMUNITY feature and INVITES_DISABLED feature at the "
"same time due to a discord limitation."
)
if not isinstance(invites_disabled, bool):
raise TypeError("invites_disabled must be a bool")
if invites_disabled:
features.add("INVITES_DISABLED")
else:
features.discard("INVITES_DISABLED")

fields["features"] = list(features)

if premium_progress_bar_enabled is not MISSING:
Expand Down
1 change: 1 addition & 0 deletions disnake/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class _GuildOptional(TypedDict, total=False):
"HAS_DIRECTORY_ENTRY",
"HUB",
"INVITE_SPLASH",
"INVITES_DISABLED",
"LINKED_TO_HUB",
"MEMBER_PROFILES", # not sure what this does, if anything
"MEMBER_VERIFICATION_GATE_ENABLED",
Expand Down