backport(Guild): add fetchVanityCode (#2871)

This commit is contained in:
SpaceEEC
2018-10-04 00:31:20 +02:00
committed by Isabella
parent 1e85887229
commit c6201ee41b
4 changed files with 27 additions and 0 deletions

View File

@@ -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' :

View File

@@ -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>>}

View File

@@ -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`,

1
typings/index.d.ts vendored
View File

@@ -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>;