Skip to content

Commit

Permalink
backport(Guild): add fetchVanityCode (#2871)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC authored and Lewdcario committed Oct 3, 2018
1 parent 1e85887 commit c6201ee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/client/rest/RESTMethods.js
Expand Up @@ -684,6 +684,11 @@ class RESTMethods {
});
}

getGuildVanityCode(guild) {
return this.rest.makeRequest('get', Endpoints.Guild(guild).vanityURL, true)
.then(res => res.code);
}

pruneGuildMembers(guild, days, dry, reason) {
return this.rest.makeRequest(dry ?
'get' :
Expand Down
20 changes: 20 additions & 0 deletions src/structures/Guild.js
Expand Up @@ -504,6 +504,26 @@ class Guild {
return this.client.rest.methods.getGuildInvites(this);
}

/**
* 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('This guild does not have the VANITY_URL feature enabled.'));
}
return this.client.rest.methods.getGuildVanityCode(this);
}


/**
* Fetch all webhooks for the guild.
* @returns {Promise<Collection<Snowflake, Webhook>>}
Expand Down
1 change: 1 addition & 0 deletions src/util/Constants.js
Expand Up @@ -144,6 +144,7 @@ const Endpoints = exports.Endpoints = {
roles: `${base}/roles`,
emojis: `${base}/emojis`,
search: `${base}/messages/search`,
vanityURL: `${base}/vanity-url`,
voiceRegions: `${base}/regions`,
webhooks: `${base}/webhooks`,
ack: `${base}/ack`,
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -537,6 +537,7 @@ declare module 'discord.js' {
public fetchInvites(): Promise<Collection<Snowflake, Invite>>;
public fetchMember(user: UserResolvable, cache?: boolean): Promise<GuildMember>;
public fetchMembers(query?: string, limit?: number): Promise<Guild>;
public fetchVanityCode(): Promise<string>;
public fetchVoiceRegions(): Promise<Collection<string, VoiceRegion>>;
public fetchWebhooks(): Promise<Collection<Snowflake, Webhook>>;
public leave(): Promise<Guild>;
Expand Down

0 comments on commit c6201ee

Please sign in to comment.