Skip to content

Commit f3cfce0

Browse files
authored
feat: Implement helper methods for invites (#1098)
1 parent 1de54e9 commit f3cfce0

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

interactions/api/http/invite.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ async def get_invite(
2424
"""
2525
Gets a Discord invite using its code.
2626
27-
.. note:: with_expiration is currently broken, the API will always return expiration_date.
28-
2927
:param invite_code: A string representing the invite code.
3028
:param with_counts: Whether approximate_member_count and approximate_presence_count are returned.
31-
:param with_expiration: Whether the invite's expiration is returned.
29+
:param with_expiration: Whether the invite's expiration date is returned.
3230
:param guild_scheduled_event_id: A guild scheduled event's ID.
3331
"""
3432
params_set = {

interactions/api/models/guild.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,6 +2830,66 @@ async def get_full_audit_logs(
28302830

28312831
return AuditLogs(**_audit_log_dict)
28322832

2833+
async def get_invite(
2834+
self,
2835+
invite_code: str,
2836+
with_counts: Optional[bool] = MISSING,
2837+
with_expiration: Optional[bool] = MISSING,
2838+
guild_scheduled_event_id: Optional[int] = MISSING,
2839+
) -> "Invite":
2840+
"""
2841+
Gets the invite using its code.
2842+
2843+
:param str invite_code: A string representing the invite code.
2844+
:param Optional[bool] with_counts: Whether approximate_member_count and approximate_presence_count are returned.
2845+
:param Optional[bool] with_expiration: Whether the invite's expiration date is returned.
2846+
:param Optional[int] guild_scheduled_event_id: A guild scheduled event's ID.
2847+
:return: An invite
2848+
:rtype: Invite
2849+
"""
2850+
if not self._client:
2851+
raise LibraryException(code=13)
2852+
2853+
_with_counts = with_counts if with_counts is not MISSING else None
2854+
_with_expiration = with_expiration if with_expiration is not MISSING else None
2855+
_guild_scheduled_event_id = (
2856+
guild_scheduled_event_id if guild_scheduled_event_id is not MISSING else None
2857+
)
2858+
2859+
res = await self._client.get_invite(
2860+
invite_code=invite_code,
2861+
with_counts=_with_counts,
2862+
with_expiration=_with_expiration,
2863+
guild_scheduled_event_id=_guild_scheduled_event_id,
2864+
)
2865+
2866+
return Invite(**res, _client=self._client)
2867+
2868+
async def delete_invite(self, invite_code: str, reason: Optional[str] = None) -> None:
2869+
"""
2870+
Deletes the invite using its code.
2871+
2872+
:param str invite_code: A string representing the invite code.
2873+
:param Optional[str] reason: The reason of the deletion
2874+
"""
2875+
if not self._client:
2876+
raise LibraryException(code=13)
2877+
2878+
await self._client.delete_invite(invite_code=invite_code, reason=reason)
2879+
2880+
async def get_invites(self) -> List["Invite"]:
2881+
"""
2882+
Gets invites of the guild.
2883+
2884+
:return: A list of guild invites
2885+
:rtype: List[Invite]
2886+
"""
2887+
if not self._client:
2888+
raise LibraryException(code=13)
2889+
2890+
res = await self._client.get_guild_invites(guild_id=int(self.id))
2891+
return [Invite(**_, _client=self._client) for _ in res]
2892+
28332893
@property
28342894
def icon_url(self) -> Optional[str]:
28352895
"""

0 commit comments

Comments
 (0)