Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 5c4ab09

Browse files
Sigmanificientzunda-arrowtrag1c
authored
✨ Get Invite & Delete invite (#393)
* ✨ Added get_invite endpoint * ✨ Added delete_invite endpoint * ✨ Added invite.delete * Update pincer/objects/guild/guild.py Co-authored-by: Lunarmagpie <[email protected]> * 🎨 black * Update pincer/objects/guild/guild.py Co-authored-by: trag1c <[email protected]> * Update pincer/objects/guild/guild.py Co-authored-by: trag1c <[email protected]> * 📝 Adding core param * 🐛 Fixing async/await Co-authored-by: Lunarmagpie <[email protected]> Co-authored-by: trag1c <[email protected]>
1 parent f875081 commit 5c4ab09

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

pincer/objects/guild/guild.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,23 @@ async def get_invites(self) -> AsyncGenerator[Invite, None]:
12791279
for invite_data in data:
12801280
yield Invite.from_dict(invite_data)
12811281

1282+
async def get_invite(self, code: str) -> Invite:
1283+
"""|coro|
1284+
Returns an Invite object for the given invite code.
1285+
1286+
Parameters
1287+
----------
1288+
code : :class:`str`
1289+
The invite code to get the invite for.
1290+
1291+
Returns
1292+
-------
1293+
:class:`~pincer.objects.guild.invite.Invite`
1294+
The invite object.
1295+
"""
1296+
data = await self._http.get(f"invite/{code}")
1297+
return Invite.from_dict(data)
1298+
12821299
async def get_integrations(self) -> AsyncIterator[Integration]:
12831300
"""|coro|
12841301
Returns an async generator of integrations for the guild.
@@ -1312,6 +1329,18 @@ async def delete_integration(
13121329
headers={"X-Audit-Log-Reason": reason},
13131330
)
13141331

1332+
async def delete_invite(self, code: str):
1333+
"""|coro|
1334+
Deletes an invite.
1335+
Requires the ``MANAGE_GUILD`` intent.
1336+
1337+
Parameters
1338+
----------
1339+
code : :class:`str`
1340+
The code of the invite to delete.
1341+
"""
1342+
await self._http.delete(f"guilds/{self.id}/invites/{code}")
1343+
13151344
async def get_widget_settings(self) -> GuildWidget:
13161345
"""|coro|
13171346
Returns the guild widget settings.

pincer/objects/guild/invite.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class InviteTargetType(IntEnum):
3232
EMBEDDED_APPLICATION:
3333
An embedded application invite, e.g. poker-night etc.
3434
"""
35+
3536
STREAM = 1
3637
EMBEDDED_APPLICATION = 2
3738

@@ -51,6 +52,7 @@ class InviteStageInstance(APIObject):
5152
topic: :class:`str`
5253
the topic of the Stage instance (1-120 characters)
5354
"""
55+
5456
members: List[GuildMember]
5557
participant_count: int
5658
speaker_count: int
@@ -101,6 +103,7 @@ class Invite(APIObject):
101103
created_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
102104
When this invite was created
103105
"""
106+
104107
# noqa: E501
105108

106109
channel: Channel
@@ -130,3 +133,17 @@ def __str__(self) -> str:
130133
@property
131134
def link(self):
132135
return f"https://discord.gg/{self.code}"
136+
137+
async def delete(self):
138+
"""Delete this invite.
139+
140+
Raises
141+
------
142+
Forbidden
143+
You do not have permission to delete this invite
144+
NotFound
145+
This invite does not exist
146+
HTTPException
147+
Deleting the invite failed
148+
"""
149+
await self._http.delete(f"guilds/{self.guild.id}/invites/{self.code}")

0 commit comments

Comments
 (0)