Skip to content

Commit 4408e1b

Browse files
Snipy7374shiftinv
andauthored
fix: deprecate with_expiration from Client.fetch_invite (DisnakeDev#1297)
Signed-off-by: Snipy7374 <100313469+Snipy7374@users.noreply.github.com> Co-authored-by: vi <8530778+shiftinv@users.noreply.github.com>
1 parent e08cf82 commit 4408e1b

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

changelog/1296.deprecate.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate `with_expiration` query parameter of :meth:`Client.fetch_invite` as it is no longer supported from the discord API.

disnake/audit_logs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ def _convert_target_invite(self, target_id: int) -> Invite:
826826
"uses": changeset.uses,
827827
"type": 0,
828828
"channel": None,
829+
"expires_at": None,
829830
}
830831

831832
obj = Invite(

disnake/client.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,8 +2234,8 @@ async def fetch_invite(
22342234
url: Union[Invite, str],
22352235
*,
22362236
with_counts: bool = True,
2237-
with_expiration: bool = True,
22382237
guild_scheduled_event_id: Optional[int] = None,
2238+
with_expiration: bool = False,
22392239
) -> Invite:
22402240
"""|coro|
22412241
@@ -2255,12 +2255,6 @@ async def fetch_invite(
22552255
Whether to include count information in the invite. This fills the
22562256
:attr:`.Invite.approximate_member_count` and :attr:`.Invite.approximate_presence_count`
22572257
fields.
2258-
with_expiration: :class:`bool`
2259-
Whether to include the expiration date of the invite. This fills the
2260-
:attr:`.Invite.expires_at` field.
2261-
2262-
.. versionadded:: 2.0
2263-
22642258
guild_scheduled_event_id: :class:`int`
22652259
The ID of the scheduled event to include in the invite.
22662260
If not provided, defaults to the ``event`` parameter in the URL if it exists,
@@ -2280,6 +2274,14 @@ async def fetch_invite(
22802274
:class:`.Invite`
22812275
The invite from the URL/ID.
22822276
"""
2277+
if with_expiration:
2278+
utils.warn_deprecated(
2279+
"Using the `with_expiration` argument is deprecated and will "
2280+
"result in an error in future versions. "
2281+
"The `expires_at` field is always included now.",
2282+
stacklevel=2,
2283+
)
2284+
22832285
invite_id, params = utils.resolve_invite(url, with_params=True)
22842286

22852287
if not guild_scheduled_event_id:
@@ -2292,7 +2294,6 @@ async def fetch_invite(
22922294
data = await self.http.get_invite(
22932295
invite_id,
22942296
with_counts=with_counts,
2295-
with_expiration=with_expiration,
22962297
guild_scheduled_event_id=guild_scheduled_event_id,
22972298
)
22982299
return Invite.from_incomplete(state=self._connection, data=data)

disnake/http.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,12 +1912,10 @@ def get_invite(
19121912
invite_id: str,
19131913
*,
19141914
with_counts: bool = True,
1915-
with_expiration: bool = True,
19161915
guild_scheduled_event_id: Optional[int] = None,
19171916
) -> Response[invite.Invite]:
19181917
params = {
19191918
"with_counts": int(with_counts),
1920-
"with_expiration": int(with_expiration),
19211919
}
19221920
if guild_scheduled_event_id:
19231921
params["guild_scheduled_event_id"] = guild_scheduled_event_id

disnake/invite.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ class Invite(Hashable):
295295
+------------------------------------+---------------------------------------------------------------------+
296296
| :attr:`approximate_presence_count` | :meth:`Client.fetch_invite` with ``with_counts`` enabled |
297297
+------------------------------------+---------------------------------------------------------------------+
298-
| :attr:`expires_at` | :meth:`Client.fetch_invite` with ``with_expiration`` enabled |
299-
+------------------------------------+---------------------------------------------------------------------+
300298
| :attr:`guild_scheduled_event` | :meth:`Client.fetch_invite` with valid ``guild_scheduled_event_id`` |
301299
| | or valid event ID in URL or invite object |
302300
+------------------------------------+---------------------------------------------------------------------+
@@ -347,8 +345,7 @@ class Invite(Hashable):
347345
348346
Optional according to the :ref:`table <invite_attr_table>` above.
349347
expires_at: Optional[:class:`datetime.datetime`]
350-
The expiration date of the invite. If the value is ``None`` when received through
351-
:meth:`Client.fetch_invite` with ``with_expiration`` enabled, the invite will never expire.
348+
The expiration date of the invite. If the value is ``None`` the invite will never expire.
352349
353350
.. versionadded:: 2.0
354351

disnake/types/invite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ class Invite(_InviteMetadata):
4040
target_application: NotRequired[PartialAppInfo]
4141
approximate_presence_count: NotRequired[int]
4242
approximate_member_count: NotRequired[int]
43-
expires_at: NotRequired[Optional[str]]
43+
expires_at: Optional[str]
4444
guild_scheduled_event: NotRequired[GuildScheduledEvent]

0 commit comments

Comments
 (0)