diff --git a/src/structures/Guild.js b/src/structures/Guild.js index b55df22..c2f13c9 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -1620,6 +1620,33 @@ class Guild extends AnonymousGuild { ); } + /** + * Set the vanity URL to this guild. + * Resolves with an object containing the vanity URL invite code and the use count. + * @param {string} [code=''] Vanity URL code + * @returns {Promise} + * @example + * // Set invite code + * guild.setVanityCode('elysia') + * .then(res => { + * console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`); + * }) + * .catch(console.error); + */ + async setVanityCode(code = '') { + if (!this.features.includes('VANITY_URL')) { + throw new Error('VANITY_URL'); + } + if (typeof code !== 'string') throw new TypeError('INVALID_VANITY_URL_CODE'); + const data = await this.client.api.guilds(this.id, 'vanity-url').patch({ + data: { code }, + }); + this.vanityURLCode = data.code; + this.vanityURLUses = data.uses; + + return data; + } + toJSON() { const json = super.toJSON({ available: false, diff --git a/typings/index.d.ts b/typings/index.d.ts index 7cca0f1..53c73b7 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1441,6 +1441,7 @@ export class Guild extends AnonymousGuild { reason?: string, ): Promise; public setWidgetSettings(settings: GuildWidgetSettingsData, reason?: string): Promise; + public setVanityCode(code?: string): Promise; public toJSON(): unknown; }