feat(Guild): setVanityCode

Co-Authored-By: Chino-chan <93425627+Tungchaphet@users.noreply.github.com>

#533
This commit is contained in:
Elysia 2023-02-14 12:41:06 +07:00
parent 0361dfa96d
commit a8c08822ff
2 changed files with 28 additions and 0 deletions

View File

@ -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<Vanity>}
* @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,

1
typings/index.d.ts vendored
View File

@ -1441,6 +1441,7 @@ export class Guild extends AnonymousGuild {
reason?: string,
): Promise<Guild>;
public setWidgetSettings(settings: GuildWidgetSettingsData, reason?: string): Promise<Guild>;
public setVanityCode(code?: string): Promise<Vanity>;
public toJSON(): unknown;
}