aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-04-30 07:16:11 -0400
committerRapptz <[email protected]>2017-04-30 07:17:00 -0400
commitba2dad209316aeaecb9e1d315bb03a09794c5e2c (patch)
tree548dceed0b68850a6de8e2781146ebe110b029d8
parentChanged audit_log to audit_logs in documentation (diff)
downloaddiscord.py-ba2dad209316aeaecb9e1d315bb03a09794c5e2c.tar.xz
discord.py-ba2dad209316aeaecb9e1d315bb03a09794c5e2c.zip
Add support for setting and retrieving guild vanity invites.
-rw-r--r--discord/guild.py55
-rw-r--r--discord/http.py7
-rw-r--r--docs/api.rst2
3 files changed, 64 insertions, 0 deletions
diff --git a/discord/guild.py b/discord/guild.py
index a044bdd9..9e79ac64 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -1003,6 +1003,61 @@ class Guild(Hashable):
"""
yield from self._state.http.unban(user.id, self.id)
+ @asyncio.coroutine
+ def vanity_invite(self):
+ """|coro|
+
+ Returns the guild's special vanity invite.
+
+ The guild must be partnered, i.e. have 'VANITY_URL' in
+ :attr:`~Guild.features`.
+
+ You must have :attr:`Permissions.manage_guild` to use this as well.
+
+ Returns
+ --------
+ :class:`Invite`
+ The special vanity invite.
+
+ Raises
+ -------
+ Forbidden
+ You do not have the proper permissions to get this.
+ HTTPException
+ Retrieving the vanity invite failed.
+ """
+
+ # we start with { code: abc }
+ payload = yield from self._state.http.get_vanity_code(self.id)
+ payload['guild'] = self
+ payload['channel'] = self.default_channel
+ payload['revoked'] = False
+ payload['temporary'] = False
+ payload['max_uses'] = 0
+ payload['max_age'] = 0
+ return Invite(state=self._state, data=payload)
+
+ @asyncio.coroutine
+ def change_vanity_invite(self, new_code):
+ """|coro|
+
+ Changes the guild's special vanity invite.
+
+ The guild must be partnered, i.e. have 'VANITY_URL' in
+ :attr:`~Guild.features`.
+
+ You must have :attr:`Permissions.manage_guild` to use this as well.
+
+ Raises
+ -------
+ Forbidden
+ You do not have the proper permissions to set this.
+ HTTPException
+ Setting the vanity invite failed.
+ """
+
+ yield from self._state.http.change_vanity_code(self.id, new_code)
+
def ack(self):
"""|coro|
diff --git a/discord/http.py b/discord/http.py
index eab37c62..12252eb8 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -531,6 +531,13 @@ class HTTPClient:
def get_bans(self, guild_id):
return self.request(Route('GET', '/guilds/{guild_id}/bans', guild_id=guild_id))
+ def get_vanity_code(self, guild_id):
+ return self.request(Route('GET', '/guilds/{guild_id}/vanity-url', guild_id=guild_id))
+
+ def change_vanity_code(self, guild_id, code):
+ payload = { 'code': code }
+ return self.request(Route('PATCH', '/guilds/{guild_id}/vanity-url', guild_id=guild_id), json=payload)
+
def prune_members(self, guild_id, days):
params = {
'days': days
diff --git a/docs/api.rst b/docs/api.rst
index fbf16e92..509c10df 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -1320,6 +1320,8 @@ this goal, it must make use of a couple of data classes that aid in this goal.
*str* – The guild's vanity URL.
+ See also :meth:`Guild.vanity_invite` and :meth:`Guild.change_vanity_invite`.
+
.. attribute:: position
*int* – The position of a :class:`Role` or :class:`abc.GuildChannel`.