From c3fabe4a7f4f24319f32167b12cf4f975a88d0cc Mon Sep 17 00:00:00 2001 From: Johnson Chen Date: Mon, 20 Apr 2020 00:58:59 +1000 Subject: [PATCH] feat: add Guild.fetchVanityData() --- src/structures/Guild.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 08aeb46d2..e0422007e 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -746,6 +746,28 @@ class Guild extends Base { .then(res => res.code); } + /** + * Fetches the vanity url invite object to this guild. + * Resolves with an object containing the vanity url invite code, not the full url and the use count. + * @returns {Promise<{ code: ?string, uses: ?number }>} + * @example + * // Fetch invite data + * guild.fetchVanityData() + * .then(res => { + * console.log(`Vanity URL: https://discord.gg/${res.code}`); + * }) + * .catch(console.error); + */ + fetchVanityData() { + 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); + } + /** * Fetches all webhooks for the guild. * @returns {Promise>}