feat: add guild.fetchVanityCode() (#2732)

* Error for guild.fetchVanityURL feature not enabled

* added GET/guilds/{guild.id}/vanity-url endpoint

* fix: code conventions

* adopted suggestion

* Changed error message according to change request

* Renamed method

to indicate that only the code is fetched, not the entire url.

* Update Guild.js
This commit is contained in:
Florian
2018-08-18 13:57:58 +02:00
committed by Crawl
parent 94214fa733
commit f8057b01cb
2 changed files with 22 additions and 0 deletions

View File

@@ -434,6 +434,26 @@ class Guild extends Base {
});
}
/**
* Fetches the vanity url invite code to this guild.
* Resolves with a string matching the vanity url invite code, not the full url.
* @returns {Promise<string>}
* @example
* // Fetch invites
* guild.fetchVanityCode()
* .then(code => {
* console.log(`Vanity URL: https://discord.gg/${code}`);
* })
* .catch(console.error);
*/
fetchVanityCode() {
if (!this.features.includes('VANITY_URL')) {
return Promise.reject(new Error('VANITY_URL'));
}
return this.client.api.guilds(this.id, 'vanity-url').get()
.then(res => res.code);
}
/**
* Fetches all webhooks for the guild.
* @returns {Promise<Collection<Snowflake, Webhook>>}