Discord.js: Add function to get vanity URL uses

Created on 9 Apr 2020  路  5Comments  路  Source: discordjs/discord.js

Is your feature request related to a problem? Please describe.
I want to get the uses of a vanity URL, but there is no function for that.

Describe the ideal solution
Add a function Guild.fetchVanityUses() that gets the uses of a vanity URL, if any.

Describe alternatives you've considered
It is already possible to get vanity invites via client.fetchInvite(server.vanityURLCode), but the .uses is always null. Instead of the extra function the implementation could fill that field. Alternatively the fetchInvites function could be changed to include the vanity URL invite and its uses.

Additional context
The Discord API supports this: https://discordapp.com/developers/docs/resources/guild#get-guild-vanity-url
There is this code in https://github.com/discordjs/discord.js/blob/master/src/structures/Guild.js#L726-L746:

  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);
  }

so it should be relatively easy to add

  fetchVanityUses() {
    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.uses);
  }
API changes enhancement

Most helpful comment

The linked PR #4103 will provide the ability to fetch the vanity data from the /guilds/{guild.id}/vanity-url endpoint - there's really no need to discuss it further here or implement a workaround by Invite.

All 5 comments

You could just make a parameter based function yourself:
fetchVanityUses(guild) {
  if (guild.vanityURLCode) {
    guild.fetchInvites()
      .then(result = invites => console.log(invites.find(invite => invite.code === guild.vanityURLCode)))
      .catch(console.error)
    return(result)
  } else {
    return('0')
  }
}

Or maybe just have a function that fetches the vanity invite?
Which of course returns Promise<Invite>, which then you can resolve to get uses.

The linked PR #4103 will provide the ability to fetch the vanity data from the /guilds/{guild.id}/vanity-url endpoint - there's really no need to discuss it further here or implement a workaround by Invite.

how do we change custom url?

https://discord.com/developers/docs/resources/guild#modify-guild does not seem to have anything documented that could change the vanity url, we can only implement features discord supports (and documents)

If you need help with discord.js installation or usage, please go to the discord.js Discord server instead:
https://discord.gg/bRCvFy9
This issue tracker is only for bug reports and enhancement suggestions. You won't receive any basic help here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrandonCookeDev picture BrandonCookeDev  路  3Comments

Dmitry221060 picture Dmitry221060  路  3Comments

Lombra picture Lombra  路  3Comments

ghost picture ghost  路  3Comments

Dmitry221060 picture Dmitry221060  路  3Comments