Skip to content

Commit ca13ea3

Browse files
committed
Add support for guest invites
1 parent 2175bd5 commit ca13ea3

File tree

8 files changed

+98
-2
lines changed

8 files changed

+98
-2
lines changed

discord/abc.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
from .voice_client import VoiceClient, VoiceProtocol
6161
from .sticker import GuildSticker, StickerItem
6262
from . import utils
63+
from .flags import GuildInviteFlags
6364

6465
__all__ = (
6566
'Snowflake',
@@ -1257,6 +1258,7 @@ async def create_invite(
12571258
target_type: Optional[InviteTarget] = None,
12581259
target_user: Optional[User] = None,
12591260
target_application_id: Optional[int] = None,
1261+
guest_invite: bool = False,
12601262
) -> Invite:
12611263
"""|coro|
12621264
@@ -1295,6 +1297,12 @@ async def create_invite(
12951297
The id of the embedded application for the invite, required if ``target_type`` is :attr:`.InviteTarget.embedded_application`.
12961298
12971299
.. versionadded:: 2.0
1300+
guest_invite: :class:`bool`
1301+
Whether the invite is a guest invite.
1302+
1303+
This is only available to guilds that contain ``GUESTS_ENABLED`` in :attr:`.Guild.features`.
1304+
1305+
.. versionadded:: 2.6
12981306
12991307
Raises
13001308
-------
@@ -1312,6 +1320,10 @@ async def create_invite(
13121320
if target_type is InviteTarget.unknown:
13131321
raise ValueError('Cannot create invite with an unknown target type')
13141322

1323+
flags = GuildInviteFlags._from_value(0)
1324+
if guest_invite:
1325+
flags.is_guest_invite = True
1326+
13151327
data = await self._state.http.create_invite(
13161328
self.id,
13171329
reason=reason,
@@ -1322,6 +1334,7 @@ async def create_invite(
13221334
target_type=target_type.value if target_type else None,
13231335
target_user_id=target_user.id if target_user else None,
13241336
target_application_id=target_application_id,
1337+
flags=flags.value,
13251338
)
13261339
return Invite.from_incomplete(data=data, state=self._state)
13271340

discord/flags.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
'AppInstallationType',
6565
'SKUFlags',
6666
'EmbedFlags',
67+
'GuildInviteFlags',
6768
)
6869

6970
BF = TypeVar('BF', bound='BaseFlags')
@@ -2397,3 +2398,59 @@ def content_inventory_entry(self):
23972398
longer displayed.
23982399
"""
23992400
return 1 << 5
2401+
2402+
2403+
class GuildInviteFlags(BaseFlags):
2404+
r"""Wraps up the Discord Guild Invite flags
2405+
2406+
.. versionadded:: 2.6
2407+
2408+
.. container:: operations
2409+
2410+
.. describe:: x == y
2411+
2412+
Checks if two GuildInviteFlags are equal.
2413+
2414+
.. describe:: x != y
2415+
2416+
Checks if two GuildInviteFlags are not equal.
2417+
2418+
.. describe:: x | y, x |= y
2419+
2420+
Returns a GuildInviteFlags instance with all enabled flags from
2421+
both x and y.
2422+
2423+
.. describe:: x ^ y, x ^= y
2424+
2425+
Returns a GuildInviteFlags instance with only flags enabled on
2426+
only one of x or y, not on both.
2427+
2428+
.. describe:: ~x
2429+
2430+
Returns a GuildInviteFlags instance with all flags inverted from x.
2431+
2432+
.. describe:: hash(x)
2433+
2434+
Returns the flag's hash.
2435+
2436+
.. describe:: iter(x)
2437+
2438+
Returns an iterator of ``(name, value)`` pairs. This allows it
2439+
to be, for example, constructed as a dict or a list of pairs.
2440+
Note that aliases are not shown.
2441+
2442+
.. describe:: bool(b)
2443+
2444+
Returns whether any flag is set to ``True``.
2445+
2446+
Attributes
2447+
----------
2448+
value: :class:`int`
2449+
The raw value. You should query flags via the properties
2450+
rather than using this raw value.
2451+
"""
2452+
2453+
@flag_value
2454+
def is_guest_invite(self):
2455+
""":class:`bool`: Returns ``True`` if this is a guest invite for a voice channel."""
2456+
return 1 << 0

discord/http.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,7 @@ def create_invite(
18341834
target_type: Optional[invite.InviteTargetType] = None,
18351835
target_user_id: Optional[Snowflake] = None,
18361836
target_application_id: Optional[Snowflake] = None,
1837+
flags: Optional[int] = None,
18371838
) -> Response[invite.Invite]:
18381839
r = Route('POST', '/channels/{channel_id}/invites', channel_id=channel_id)
18391840
payload = {
@@ -1852,6 +1853,9 @@ def create_invite(
18521853
if target_application_id:
18531854
payload['target_application_id'] = str(target_application_id)
18541855

1856+
if flags is not None:
1857+
payload['flags'] = flags
1858+
18551859
return self.request(r, reason=reason, json=payload)
18561860

18571861
def get_invite(

discord/invite.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from .enums import ChannelType, NSFWLevel, VerificationLevel, InviteTarget, InviteType, try_enum
3333
from .appinfo import PartialAppInfo
3434
from .scheduled_event import ScheduledEvent
35+
from .flags import GuildInviteFlags
3536

3637
__all__ = (
3738
'PartialInviteChannel',
@@ -379,6 +380,7 @@ class Invite(Hashable):
379380
'scheduled_event',
380381
'scheduled_event_id',
381382
'type',
383+
'_flags',
382384
)
383385

384386
BASE = 'https://discord.gg'
@@ -432,6 +434,7 @@ def __init__(
432434
else None
433435
)
434436
self.scheduled_event_id: Optional[int] = self.scheduled_event.id if self.scheduled_event else None
437+
self._flags: int = data.get('flags', 0)
435438

436439
@classmethod
437440
def from_incomplete(cls, *, state: ConnectionState, data: InvitePayload) -> Self:
@@ -523,6 +526,14 @@ def url(self) -> str:
523526
url += '?event=' + str(self.scheduled_event_id)
524527
return url
525528

529+
@property
530+
def flags(self) -> GuildInviteFlags:
531+
""":class:`GuildInviteFlags`: Returns the flags for this guild invite.
532+
533+
.. versionadded:: 2.6
534+
"""
535+
return GuildInviteFlags._from_value(self._flags)
536+
526537
def set_scheduled_event(self, scheduled_event: Snowflake, /) -> Self:
527538
"""Sets the scheduled event for this invite.
528539

discord/member.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ class Member(discord.abc.Messageable, _UserTag):
238238
----------
239239
joined_at: Optional[:class:`datetime.datetime`]
240240
An aware datetime object that specifies the date and time in UTC that the member joined the guild.
241-
If the member left and rejoined the guild, this will be the latest date. In certain cases, this can be ``None``.
241+
If the member left and rejoined the guild, this will be the latest date.
242+
This can be ``None``, such as when the member is a guest.
242243
activities: Tuple[Union[:class:`BaseActivity`, :class:`Spotify`]]
243244
The activities that the user is currently doing.
244245

discord/types/invite.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Invite(IncompleteInvite, total=False):
6565
target_application: PartialAppInfo
6666
guild_scheduled_event: GuildScheduledEvent
6767
type: InviteType
68+
flags: NotRequired[int]
6869

6970

7071
class InviteWithCounts(Invite, _GuildPreviewUnique):
@@ -84,6 +85,7 @@ class GatewayInviteCreate(TypedDict):
8485
target_type: NotRequired[InviteTargetType]
8586
target_user: NotRequired[PartialUser]
8687
target_application: NotRequired[PartialAppInfo]
88+
flags: NotRequired[int]
8789

8890

8991
class GatewayInviteDelete(TypedDict):

discord/types/member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Nickname(TypedDict):
3434

3535
class PartialMember(TypedDict):
3636
roles: SnowflakeList
37-
joined_at: str
37+
joined_at: Optional[str] # null if guest
3838
deaf: bool
3939
mute: bool
4040
flags: int

docs/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5734,6 +5734,14 @@ EmbedFlags
57345734
.. autoclass:: EmbedFlags()
57355735
:members:
57365736

5737+
GuildInviteFlags
5738+
~~~~~~~~~~~~~~~~
5739+
5740+
.. attributetable:: GuildInviteFlags
5741+
5742+
.. autoclass:: GuildInviteFlags(
5743+
:members:
5744+
57375745
ForumTag
57385746
~~~~~~~~~
57395747

0 commit comments

Comments
 (0)