diff --git a/discord/guild.py b/discord/guild.py index a044bdd98..9e79ac643 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 eab37c629..12252eb85 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 fbf16e92e..509c10df6 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`.