From b9dc85e6f72f26dcc17f5d0808cfe35d439b3104 Mon Sep 17 00:00:00 2001 From: Andrin <65789180+Puncher1@users.noreply.github.com> Date: Fri, 17 May 2024 19:31:26 +0200 Subject: [PATCH] Add type attribute to Invite --- discord/enums.py | 6 ++++++ discord/invite.py | 10 ++++++++-- discord/types/invite.py | 2 ++ docs/api.rst | 20 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/discord/enums.py b/discord/enums.py index f7989a195..80e27763d 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -823,6 +823,12 @@ class PollLayoutType(Enum): default = 1 +class InviteType(Enum): + guild = 0 + group_dm = 1 + friend = 2 + + def create_unknown_value(cls: Type[E], val: Any) -> E: value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below name = f'unknown_{val}' diff --git a/discord/invite.py b/discord/invite.py index 1c18e4187..1d8dd1c8e 100644 --- a/discord/invite.py +++ b/discord/invite.py @@ -29,7 +29,7 @@ from .asset import Asset from .utils import parse_time, snowflake_time, _get_as_snowflake from .object import Object from .mixins import Hashable -from .enums import ChannelType, NSFWLevel, VerificationLevel, InviteTarget, try_enum +from .enums import ChannelType, NSFWLevel, VerificationLevel, InviteTarget, InviteType, try_enum from .appinfo import PartialAppInfo from .scheduled_event import ScheduledEvent @@ -296,6 +296,10 @@ class Invite(Hashable): Attributes ----------- + type: :class:`InviteType` + The type of the invite. + + .. versionadded: 2.4 max_age: Optional[:class:`int`] How long before the invite expires in seconds. A value of ``0`` indicates that it doesn't expire. @@ -374,6 +378,7 @@ class Invite(Hashable): 'expires_at', 'scheduled_event', 'scheduled_event_id', + 'type', ) BASE = 'https://discord.gg' @@ -387,6 +392,7 @@ class Invite(Hashable): channel: Optional[Union[PartialInviteChannel, GuildChannel]] = None, ): self._state: ConnectionState = state + self.type: InviteType = try_enum(InviteType, data.get('type', 0)) self.max_age: Optional[int] = data.get('max_age') self.code: str = data['code'] self.guild: Optional[InviteGuildType] = self._resolve_guild(data.get('guild'), guild) @@ -496,7 +502,7 @@ class Invite(Hashable): def __repr__(self) -> str: return ( - f'' ) diff --git a/discord/types/invite.py b/discord/types/invite.py index b53ca374c..f5f00078e 100644 --- a/discord/types/invite.py +++ b/discord/types/invite.py @@ -35,6 +35,7 @@ from .user import PartialUser from .appinfo import PartialAppInfo InviteTargetType = Literal[1, 2] +InviteType = Literal[0, 1, 2] class _InviteMetadata(TypedDict, total=False): @@ -63,6 +64,7 @@ class Invite(IncompleteInvite, total=False): target_type: InviteTargetType target_application: PartialAppInfo guild_scheduled_event: GuildScheduledEvent + type: InviteType class InviteWithCounts(Invite, _GuildPreviewUnique): diff --git a/docs/api.rst b/docs/api.rst index e8a00b7e4..87047f463 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -3623,6 +3623,26 @@ of :class:`enum.Enum`. The default layout. + +.. class:: InviteType + + Represents the type of an invite. + + .. versionadded:: 2.4 + + .. attribute:: guild + + The invite is a guild invite. + + .. attribute:: group_dm + + The invite is a group DM invite. + + .. attribute:: friend + + The invite is a friend invite. + + .. _discord-api-audit-logs: Audit Log Data