mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
backport(Guild): add fetchVanityCode (#2871)
This commit is contained in:
@@ -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' :
|
||||
|
||||
@@ -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>>}
|
||||
|
||||
@@ -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
1
typings/index.d.ts
vendored
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user