Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ These changes are available on the `master` branch, but have not yet been releas

### Changed

- Inline `_InviteMetadata` fields into `IncompleteInvite`.
([#3313](https://github.com/Pycord-Development/pycord/pull/3313))
- Accept `IncompleteInvite` instead of `VanityInvite` in `Invite.__init__`.
([#3313](https://github.com/Pycord-Development/pycord/pull/3313))

### Fixed

- Fix `TypeError` when accessing `ApplicationCommand.guild_only` or
Expand All @@ -22,6 +27,9 @@ These changes are available on the `master` branch, but have not yet been releas

### Deprecated

- Deprecated `Invite.id` in favor of `Invite.code`.
([#3313](https://github.com/Pycord-Development/pycord/pull/3313))

### Removed

## [2.8.1] - 2026-07-25
Expand Down
10 changes: 9 additions & 1 deletion discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
Tuple,
TypeVar,
Union,
cast,
overload,
)

Expand Down Expand Up @@ -121,6 +122,7 @@
from .types.guild import Guild as GuildPayload
from .types.guild import GuildFeature, MFALevel
from .types.guild import ModifyIncidents as ModifyIncidentsPayload
from .types.invite import IncompleteInvite
from .types.member import Member as MemberPayload
from .types.threads import Thread as ThreadPayload
from .types.voice import VoiceState as GuildVoiceState
Expand Down Expand Up @@ -3786,7 +3788,13 @@ async def vanity_invite(self) -> Invite | None:
payload["max_uses"] = 0
payload["max_age"] = 0
payload["uses"] = payload.get("uses", 0)
return Invite(state=self._state, data=payload, guild=self, channel=channel)

return Invite(
state=self._state,
data=cast("IncompleteInvite", payload),
guild=self,
channel=channel,
)

# TODO: use MISSING when async iterators get refactored
def audit_logs(
Expand Down
46 changes: 25 additions & 21 deletions discord/invite.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import os
from typing import TYPE_CHECKING, TypeVar, Union

from typing_extensions import override
from typing_extensions import deprecated, override

from .appinfo import PartialAppInfo
from .asset import Asset
Expand Down Expand Up @@ -62,12 +62,12 @@
from .state import ConnectionState
from .types.channel import PartialChannel as InviteChannelPayload
from .types.invite import GatewayInvite as GatewayInvitePayload
from .types.invite import IncompleteInvite as IncompleteInvitePayload
from .types.invite import Invite as InvitePayload
from .types.invite import InviteGuild as InviteGuildPayload
from .types.invite import (
InviteTargetUsersJobStatus as InviteTargetUsersJobStatusPayload,
)
from .types.invite import VanityInvite as VanityInvitePayload
from .types.role import Role as RolePayload
from .types.scheduled_events import ScheduledEvent as ScheduledEventPayload
from .types.snowflake import Snowflake
Expand Down Expand Up @@ -512,25 +512,25 @@ class Invite(Hashable):
"""

__slots__ = (
"max_age",
"code",
"guild",
"revoked",
"created_at",
"uses",
"temporary",
"max_uses",
"inviter",
"channel",
"target_user",
"target_type",
"_state",
"approximate_member_count",
"approximate_presence_count",
"scheduled_event",
"target_application",
"channel",
"code",
"created_at",
"expires_at",
"guild",
"inviter",
"max_age",
"max_uses",
"revoked",
"roles",
"scheduled_event",
"target_application",
"target_type",
"target_user",
"temporary",
"uses",
)

BASE = "https://discord.gg"
Expand All @@ -539,7 +539,7 @@ def __init__(
self,
*,
state: ConnectionState,
data: InvitePayload | VanityInvitePayload,
data: InvitePayload | IncompleteInvitePayload,
guild: PartialInviteGuild | Guild | None = None,
channel: PartialInviteChannel | GuildChannel | None = None,
):
Expand Down Expand Up @@ -689,7 +689,7 @@ def _resolve_roles(
return [Object(role_id) for role_id in role_ids]

def __str__(self) -> str:
return self.url
Comment thread
vmphase marked this conversation as resolved.
Comment thread
vmphase marked this conversation as resolved.
return self.url if self.code is not None else ""

def __repr__(self) -> str:
return (
Expand All @@ -705,13 +705,18 @@ def __hash__(self) -> int:
return hash(self.code)

@property
def id(self) -> str:
@deprecated(
"Invite.id is deprecated since version 2.9, consider using Invite.code instead."
)
def id(self) -> str: # type: ignore[override]
Comment thread
vmphase marked this conversation as resolved.
"""Returns the proper code portion of the invite."""
return self.code
return self.code or ""

@property
def url(self) -> str:
"""A property that retrieves the invite URL."""
if self.code is None:
raise ValueError("Cannot build an invite URL when code is None")
return f"{self.BASE}/{self.code}{f'?event={self.scheduled_event.id}' if self.scheduled_event else ''}"

@property
Expand Down Expand Up @@ -795,7 +800,6 @@ async def delete(self, *, reason: str | None = None):
HTTPException
Revoking the invite failed.
"""

await self._state.http.delete_invite(self.code, reason=reason)

def set_scheduled_event(self, event: ScheduledEvent) -> None:
Expand Down
20 changes: 9 additions & 11 deletions discord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,20 @@
InviteTargetType = Literal[1, 2]


class _InviteMetadata(TypedDict, total=False):
uses: int
max_uses: int
max_age: int
temporary: bool
created_at: str
expires_at: str | None


class VanityInvite(_InviteMetadata):
class VanityInvite(TypedDict):
code: str | None
uses: int


class IncompleteInvite(_InviteMetadata):
class IncompleteInvite(TypedDict):
code: str
channel: PartialChannel
uses: NotRequired[int]
max_uses: NotRequired[int]
max_age: NotRequired[int]
temporary: NotRequired[bool]
created_at: NotRequired[str]
expires_at: NotRequired[str | None]


class Invite(IncompleteInvite):
Expand Down
Loading