From 2899dee295fb691ce8df48dd26fe11438b2b3e68 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Fri, 10 Sep 2021 14:47:50 +0100 Subject: [PATCH] feat: default values for setX methods --- src/structures/BaseGuildTextChannel.js | 4 ++-- src/structures/ClientUser.js | 4 ++-- src/structures/Role.js | 8 ++++---- src/structures/VoiceState.js | 16 ++++++++-------- typings/index.d.ts | 16 ++++++++-------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/structures/BaseGuildTextChannel.js b/src/structures/BaseGuildTextChannel.js index 0e1fd13f8371..ae10680ca23a 100644 --- a/src/structures/BaseGuildTextChannel.js +++ b/src/structures/BaseGuildTextChannel.js @@ -99,11 +99,11 @@ class BaseGuildTextChannel extends GuildChannel { /** * Sets whether this channel is flagged as NSFW. - * @param {boolean} nsfw Whether the channel should be considered NSFW + * @param {boolean} [nsfw=true] Whether the channel should be considered NSFW * @param {string} [reason] Reason for changing the channel's NSFW flag * @returns {Promise} */ - setNSFW(nsfw, reason) { + setNSFW(nsfw = true, reason) { return this.edit({ nsfw }, reason); } diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 4d6a63d6cce0..0611c81481f1 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -168,11 +168,11 @@ class ClientUser extends User { /** * Sets/removes the AFK flag for the client user. - * @param {boolean} afk Whether or not the user is AFK + * @param {boolean} [afk=true] Whether or not the user is AFK * @param {number|number[]} [shardId] Shard Id(s) to have the AFK flag set on * @returns {ClientPresence} */ - setAFK(afk, shardId) { + setAFK(afk = true, shardId) { return this.setPresence({ afk, shardId }); } } diff --git a/src/structures/Role.js b/src/structures/Role.js index 4d290243d98f..b75437de17db 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -244,7 +244,7 @@ class Role extends Base { /** * Sets whether or not the role should be hoisted. - * @param {boolean} hoist Whether or not to hoist the role + * @param {boolean} [hoist=true] Whether or not to hoist the role * @param {string} [reason] Reason for setting whether or not the role should be hoisted * @returns {Promise} * @example @@ -253,7 +253,7 @@ class Role extends Base { * .then(updated => console.log(`Role hoisted: ${updated.hoist}`)) * .catch(console.error); */ - setHoist(hoist, reason) { + setHoist(hoist = true, reason) { return this.edit({ hoist }, reason); } @@ -279,7 +279,7 @@ class Role extends Base { /** * Sets whether this role is mentionable. - * @param {boolean} mentionable Whether this role should be mentionable + * @param {boolean} [mentionable=true] Whether this role should be mentionable * @param {string} [reason] Reason for setting whether or not this role should be mentionable * @returns {Promise} * @example @@ -288,7 +288,7 @@ class Role extends Base { * .then(updated => console.log(`Role updated ${updated.name}`)) * .catch(console.error); */ - setMentionable(mentionable, reason) { + setMentionable(mentionable = true, reason) { return this.edit({ mentionable }, reason); } diff --git a/src/structures/VoiceState.js b/src/structures/VoiceState.js index 0dc8668b313c..a38d8beb99e4 100644 --- a/src/structures/VoiceState.js +++ b/src/structures/VoiceState.js @@ -120,21 +120,21 @@ class VoiceState extends Base { /** * Mutes/unmutes the member of this voice state. - * @param {boolean} mute Whether or not the member should be muted + * @param {boolean} [mute=true] Whether or not the member should be muted * @param {string} [reason] Reason for muting or unmuting * @returns {Promise} */ - setMute(mute, reason) { + setMute(mute = true, reason) { return this.member?.edit({ mute }, reason) ?? Promise.reject(new Error('VOICE_STATE_UNCACHED_MEMBER')); } /** * Deafens/undeafens the member of this voice state. - * @param {boolean} deaf Whether or not the member should be deafened + * @param {boolean} [deaf=true] Whether or not the member should be deafened * @param {string} [reason] Reason for deafening or undeafening * @returns {Promise} */ - setDeaf(deaf, reason) { + setDeaf(deaf = true, reason) { return this.member?.edit({ deaf }, reason) ?? Promise.reject(new Error('VOICE_STATE_UNCACHED_MEMBER')); } @@ -161,7 +161,7 @@ class VoiceState extends Base { /** * Toggles the request to speak in the channel. * Only applicable for stage channels and for the client's own voice state. - * @param {boolean} request Whether or not the client is requesting to become a speaker. + * @param {boolean} [request=true] Whether or not the client is requesting to become a speaker. * @example * // Making the client request to speak in a stage channel (raise its hand) * guild.me.voice.setRequestToSpeak(true); @@ -170,7 +170,7 @@ class VoiceState extends Base { * guild.me.voice.setRequestToSpeak(false); * @returns {Promise} */ - async setRequestToSpeak(request) { + async setRequestToSpeak(request = true) { if (this.channel?.type !== 'GUILD_STAGE_VOICE') throw new Error('VOICE_NOT_STAGE_CHANNEL'); if (this.client.user.id !== this.id) throw new Error('VOICE_STATE_NOT_OWN'); @@ -185,7 +185,7 @@ class VoiceState extends Base { /** * Suppress/unsuppress the user. Only applicable for stage channels. - * @param {boolean} suppressed - Whether or not the user should be suppressed. + * @param {boolean} [suppressed=true] Whether or not the user should be suppressed. * @example * // Making the client a speaker * guild.me.voice.setSuppressed(false); @@ -200,7 +200,7 @@ class VoiceState extends Base { * voiceState.setSuppressed(true); * @returns {Promise} */ - async setSuppressed(suppressed) { + async setSuppressed(suppressed = true) { if (typeof suppressed !== 'boolean') throw new TypeError('VOICE_STATE_INVALID_TYPE', 'suppressed'); if (this.channel?.type !== 'GUILD_STAGE_VOICE') throw new Error('VOICE_NOT_STAGE_CHANNEL'); diff --git a/typings/index.d.ts b/typings/index.d.ts index 6986bbe14cab..9706493e033b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -330,7 +330,7 @@ export class BaseGuildTextChannel extends TextBasedChannel(GuildChannel) { defaultAutoArchiveDuration: ThreadAutoArchiveDuration, reason?: string, ): Promise; - public setNSFW(nsfw: boolean, reason?: string): Promise; + public setNSFW(nsfw?: boolean, reason?: string): Promise; public setTopic(topic: string | null, reason?: string): Promise; public setType(type: Pick, reason?: string): Promise; public setType(type: Pick, reason?: string): Promise; @@ -498,7 +498,7 @@ export class ClientUser extends User { public edit(data: ClientUserEditData): Promise; public setActivity(options?: ActivityOptions): ClientPresence; public setActivity(name: string, options?: ActivityOptions): ClientPresence; - public setAFK(afk: boolean, shardId?: number | number[]): ClientPresence; + public setAFK(afk?: boolean, shardId?: number | number[]): ClientPresence; public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise; public setPresence(data: PresenceData): ClientPresence; public setStatus(status: PresenceStatusData, shardId?: number | number[]): ClientPresence; @@ -1613,8 +1613,8 @@ export class Role extends Base { public equals(role: Role): boolean; public permissionsIn(channel: GuildChannel | Snowflake): Readonly; public setColor(color: ColorResolvable, reason?: string): Promise; - public setHoist(hoist: boolean, reason?: string): Promise; - public setMentionable(mentionable: boolean, reason?: string): Promise; + public setHoist(hoist?: boolean, reason?: string): Promise; + public setMentionable(mentionable?: boolean, reason?: string): Promise; public setName(name: string, reason?: string): Promise; public setPermissions(permissions: PermissionResolvable, reason?: string): Promise; public setPosition(position: number, options?: SetRolePositionOptions): Promise; @@ -2072,12 +2072,12 @@ export class VoiceState extends Base { public suppress: boolean; public requestToSpeakTimestamp: number | null; - public setDeaf(deaf: boolean, reason?: string): Promise; - public setMute(mute: boolean, reason?: string): Promise; + public setDeaf(deaf?: boolean, reason?: string): Promise; + public setMute(mute?: boolean, reason?: string): Promise; public disconnect(reason?: string): Promise; public setChannel(channel: VoiceChannelResolvable | null, reason?: string): Promise; - public setRequestToSpeak(request: boolean): Promise; - public setSuppressed(suppressed: boolean): Promise; + public setRequestToSpeak(request?: boolean): Promise; + public setSuppressed(suppressed?: boolean): Promise; } export class Webhook extends WebhookMixin() {