Skip to content

Commit

Permalink
Added Guild Feature INVITES_DISABLED (#1613)
Browse files Browse the repository at this point in the history
Co-authored-by: Lala Sabathil <aiko@aitsys.dev>
Co-authored-by: Chicc <chicc@induo.dev>
  • Loading branch information
3 people authored Sep 6, 2022
1 parent e3e29ac commit d616545
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class Guild(Hashable):
The channel that denotes the AFK channel. ``None`` if it doesn't exist.
id: :class:`int`
The guild's ID.
invites_disabled: :class:`bool`
Indicates if the guild invites are disabled.
owner_id: :class:`int`
The guild owner's ID. Use :attr:`Guild.owner` instead.
unavailable: :class:`bool`
Expand Down Expand Up @@ -217,6 +219,7 @@ class Guild(Hashable):
student-run servers for your school or university.
- ``INTERNAL_EMPLOYEE_ONLY``: Indicates that only users with the staff badge can join the guild.
- ``INVITE_SPLASH``: Guild's invite page can have a special splash.
- ``INVITES_DISABLED``: Guild Invites are disabled.
- ``LINKED_TO_HUB``: 'Guild is linked to a hub.
- ``MEMBER_PROFILES``: Unknown.
- ``MEMBER_VERIFICATION_GATE_ENABLED``: Guild has Membership Screening enabled.
Expand Down Expand Up @@ -1018,6 +1021,11 @@ def created_at(self) -> datetime.datetime:
""":class:`datetime.datetime`: Returns the guild's creation time in UTC."""
return utils.snowflake_time(self.id)

@property
def invites_disabled(self) -> bool:
""":class:`bool`: Returns a boolean indicating if the guild invites are disabled."""
return "INVITES_DISABLED" in self.features

def get_member_named(self, name: str, /) -> Optional[Member]:
"""Returns the first member found that matches the name provided.
Expand Down Expand Up @@ -1619,6 +1627,7 @@ async def edit(
rules_channel: Optional[TextChannel] = MISSING,
public_updates_channel: Optional[TextChannel] = MISSING,
premium_progress_bar_enabled: bool = MISSING,
disable_invites: bool = MISSING
) -> Guild:
r"""|coro|
Expand Down Expand Up @@ -1696,6 +1705,8 @@ async def edit(
public updates channel.
premium_progress_bar_enabled: :class:`bool`
Whether the guild should have premium progress bar enabled.
disable_invites: :class:`bool`
Whether the guild should have server invites enabled or disabled.
reason: Optional[:class:`str`]
The reason for editing this guild. Shows up on the audit log.
Expand Down Expand Up @@ -1809,20 +1820,39 @@ async def edit(
fields["system_channel_flags"] = system_channel_flags.value

if community is not MISSING:
features = []
features = self.features.copy()
if community:
if "rules_channel_id" in fields and "public_updates_channel_id" in fields:
features.append("COMMUNITY")
if "COMMUNITY" not in features:
features.append("COMMUNITY")
else:
raise InvalidArgument(
"community field requires both rules_channel and public_updates_channel fields to be provided"
)
else:
if "COMMUNITY" in features:
if "rules_channel_id" in fields:
fields["rules_channel_id"] = None
if "public_updates_channel_id" in fields:
fields["public_updates_channel_id"] = None
features.remove("COMMUNITY")

fields["features"] = features

if premium_progress_bar_enabled is not MISSING:
fields["premium_progress_bar_enabled"] = premium_progress_bar_enabled

if disable_invites is not MISSING:
features = self.features.copy()
if disable_invites:
if not "INVITES_DISABLED" in features:
features.append("INVITES_DISABLED")
else:
if "INVITES_DISABLED" in features:
features.remove("INVITES_DISABLED")

fields["features"] = features

data = await http.edit_guild(self.id, reason=reason, **fields)
return Guild(data=data, state=self._state)

Expand Down

0 comments on commit d616545

Please sign in to comment.