Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog/1296.deprecate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate `with_expiration` query parameter of :meth:`Client.fetch_invite` as it is no longer supported from the discord API.
1 change: 1 addition & 0 deletions disnake/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ def _convert_target_invite(self, target_id: int) -> Invite:
"uses": changeset.uses,
"type": 0,
"channel": None,
"expires_at": None,
}

obj = Invite(
Expand Down
17 changes: 9 additions & 8 deletions disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,8 +2234,8 @@ async def fetch_invite(
url: Union[Invite, str],
*,
with_counts: bool = True,
with_expiration: bool = True,
guild_scheduled_event_id: Optional[int] = None,
with_expiration: bool = False,
) -> Invite:
"""|coro|

Expand All @@ -2255,12 +2255,6 @@ async def fetch_invite(
Whether to include count information in the invite. This fills the
:attr:`.Invite.approximate_member_count` and :attr:`.Invite.approximate_presence_count`
fields.
with_expiration: :class:`bool`
Whether to include the expiration date of the invite. This fills the
:attr:`.Invite.expires_at` field.

.. versionadded:: 2.0

guild_scheduled_event_id: :class:`int`
The ID of the scheduled event to include in the invite.
If not provided, defaults to the ``event`` parameter in the URL if it exists,
Expand All @@ -2280,6 +2274,14 @@ async def fetch_invite(
:class:`.Invite`
The invite from the URL/ID.
"""
if with_expiration:
utils.warn_deprecated(
"Using the `with_expiration` argument is deprecated and will "
"result in an error in future versions. "
"The `expires_at` field is always included now.",
stacklevel=2,
)

invite_id, params = utils.resolve_invite(url, with_params=True)

if not guild_scheduled_event_id:
Expand All @@ -2292,7 +2294,6 @@ async def fetch_invite(
data = await self.http.get_invite(
invite_id,
with_counts=with_counts,
with_expiration=with_expiration,
guild_scheduled_event_id=guild_scheduled_event_id,
)
return Invite.from_incomplete(state=self._connection, data=data)
Expand Down
2 changes: 0 additions & 2 deletions disnake/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1912,12 +1912,10 @@ def get_invite(
invite_id: str,
*,
with_counts: bool = True,
with_expiration: bool = True,
guild_scheduled_event_id: Optional[int] = None,
) -> Response[invite.Invite]:
params = {
"with_counts": int(with_counts),
"with_expiration": int(with_expiration),
}
if guild_scheduled_event_id:
params["guild_scheduled_event_id"] = guild_scheduled_event_id
Expand Down
5 changes: 1 addition & 4 deletions disnake/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ class Invite(Hashable):
+------------------------------------+---------------------------------------------------------------------+
| :attr:`approximate_presence_count` | :meth:`Client.fetch_invite` with ``with_counts`` enabled |
+------------------------------------+---------------------------------------------------------------------+
| :attr:`expires_at` | :meth:`Client.fetch_invite` with ``with_expiration`` enabled |
+------------------------------------+---------------------------------------------------------------------+
| :attr:`guild_scheduled_event` | :meth:`Client.fetch_invite` with valid ``guild_scheduled_event_id`` |
| | or valid event ID in URL or invite object |
+------------------------------------+---------------------------------------------------------------------+
Expand Down Expand Up @@ -347,8 +345,7 @@ class Invite(Hashable):

Optional according to the :ref:`table <invite_attr_table>` above.
expires_at: Optional[:class:`datetime.datetime`]
The expiration date of the invite. If the value is ``None`` when received through
:meth:`Client.fetch_invite` with ``with_expiration`` enabled, the invite will never expire.
The expiration date of the invite. If the value is ``None`` the invite will never expire.

.. versionadded:: 2.0

Expand Down
2 changes: 1 addition & 1 deletion disnake/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ class Invite(_InviteMetadata):
target_application: NotRequired[PartialAppInfo]
approximate_presence_count: NotRequired[int]
approximate_member_count: NotRequired[int]
expires_at: NotRequired[Optional[str]]
expires_at: Optional[str]
guild_scheduled_event: NotRequired[GuildScheduledEvent]
Loading