From b65545ad81e13cd4d35423d39773ef1498caf204 Mon Sep 17 00:00:00 2001 From: Yellowy Date: Sat, 7 Oct 2023 19:33:47 -0500 Subject: [PATCH 1/2] feat (VoiceState) add setStatus function --- src/structures/VoiceState.js | 17 +++++++++++++++++ typings/index.d.ts | 1 + 2 files changed, 18 insertions(+) diff --git a/src/structures/VoiceState.js b/src/structures/VoiceState.js index 550a5fb..9e125c1 100644 --- a/src/structures/VoiceState.js +++ b/src/structures/VoiceState.js @@ -214,6 +214,23 @@ class VoiceState extends Base { return this.guild.members.edit(this.id, { channel }, reason); } + /** + * Sets the status of the voice channel + * @param {string} status The message to set the channel status to + * @returns {Promise} + */ + async setStatus(status) { + if (this.channel?.id) { + if (this.channel?.type !== 'GUILD_VOICE') throw new Error('VOICE_NOT_GUILD_CHANNEL'); + + await this.client.api.channels(this.channel.id, 'voice-status').put({ + data: { + status, + }, + }); + } + } + /** * Toggles the request to speak in the channel. * Only applicable for stage channels and for the client's own voice state. diff --git a/typings/index.d.ts b/typings/index.d.ts index 2aac51b..2a6fcc0 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3434,6 +3434,7 @@ export class VoiceState extends Base { public setMute(mute?: boolean, reason?: string): Promise; public disconnect(reason?: string): Promise; public setChannel(channel: GuildVoiceChannelResolvable | null, reason?: string): Promise; + public setStatus(status: string): Promise; public setRequestToSpeak(request?: boolean): Promise; public setSuppressed(suppressed?: boolean): Promise; public getPreview(): Promise; From 5390ad3851135781d5f63dc8290d76484c3455ce Mon Sep 17 00:00:00 2001 From: Yellowy Date: Sat, 7 Oct 2023 19:45:27 -0500 Subject: [PATCH 2/2] feat (VoiceState) add setStatus function --- src/errors/Messages.js | 1 + src/structures/VoiceState.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index fbf5a3d..f4c8126 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -75,6 +75,7 @@ const Messages = { CLIENT_NO_CALL: 'No call exists!', VOICE_NOT_STAGE_CHANNEL: 'You are only allowed to do this in stage channels.', + VOICE_NOT_IN_GUILD: 'You are only allowed to do this in guild channels.', VOICE_STATE_NOT_OWN: 'You cannot self-deafen/mute/request to speak on VoiceStates that do not belong to the ClientUser.', diff --git a/src/structures/VoiceState.js b/src/structures/VoiceState.js index 9e125c1..90fbdb5 100644 --- a/src/structures/VoiceState.js +++ b/src/structures/VoiceState.js @@ -217,16 +217,25 @@ class VoiceState extends Base { /** * Sets the status of the voice channel * @param {string} status The message to set the channel status to + * @example + * // Setting the status to something + * guild.members.me.voice.setStatus("something") + * @example + * // Removing the status + * guild.members.me.voice.setStatus("") * @returns {Promise} */ async setStatus(status) { + // PUT https://discord.com/api/v9/channels/channelID/voice-status if (this.channel?.id) { - if (this.channel?.type !== 'GUILD_VOICE') throw new Error('VOICE_NOT_GUILD_CHANNEL'); + // You can set the staus in normal voice channels and in stages so any type starting with GUILD should work + if (!this.channel?.type.startsWith('GUILD')) throw new Error('VOICE_NOT_IN_GUILD'); await this.client.api.channels(this.channel.id, 'voice-status').put({ data: { status, }, + versioned: true, }); } }