mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Add type attribute to Invite
This commit is contained in:
parent
b0024dc866
commit
b9dc85e6f7
@ -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}'
|
||||
|
@ -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'<Invite code={self.code!r} guild={self.guild!r} '
|
||||
f'<Invite type={self.type} code={self.code!r} guild={self.guild!r} '
|
||||
f'online={self.approximate_presence_count} '
|
||||
f'members={self.approximate_member_count}>'
|
||||
)
|
||||
|
@ -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):
|
||||
|
20
docs/api.rst
20
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user