Merge pull request #867 from TheDevYellowy/main

feat (VoiceState) add setStatus function
This commit is contained in:
Elysia 2023-10-08 10:48:44 +07:00 committed by GitHub
commit af59bbc0e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -75,6 +75,7 @@ const Messages = {
CLIENT_NO_CALL: 'No call exists!', CLIENT_NO_CALL: 'No call exists!',
VOICE_NOT_STAGE_CHANNEL: 'You are only allowed to do this in stage channels.', 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: VOICE_STATE_NOT_OWN:
'You cannot self-deafen/mute/request to speak on VoiceStates that do not belong to the ClientUser.', 'You cannot self-deafen/mute/request to speak on VoiceStates that do not belong to the ClientUser.',

View File

@ -214,6 +214,32 @@ class VoiceState extends Base {
return this.guild.members.edit(this.id, { channel }, reason); 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
* @example
* // Setting the status to something
* guild.members.me.voice.setStatus("something")
* @example
* // Removing the status
* guild.members.me.voice.setStatus("")
* @returns {Promise<void>}
*/
async setStatus(status) {
// PUT https://discord.com/api/v9/channels/channelID/voice-status
if (this.channel?.id) {
// 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,
});
}
}
/** /**
* Toggles the request to speak in the channel. * Toggles the request to speak in the channel.
* Only applicable for stage channels and for the client's own voice state. * Only applicable for stage channels and for the client's own voice state.

1
typings/index.d.ts vendored
View File

@ -3434,6 +3434,7 @@ export class VoiceState extends Base {
public setMute(mute?: boolean, reason?: string): Promise<GuildMember>; public setMute(mute?: boolean, reason?: string): Promise<GuildMember>;
public disconnect(reason?: string): Promise<GuildMember>; public disconnect(reason?: string): Promise<GuildMember>;
public setChannel(channel: GuildVoiceChannelResolvable | null, reason?: string): Promise<GuildMember>; public setChannel(channel: GuildVoiceChannelResolvable | null, reason?: string): Promise<GuildMember>;
public setStatus(status: string): Promise<void>;
public setRequestToSpeak(request?: boolean): Promise<void>; public setRequestToSpeak(request?: boolean): Promise<void>;
public setSuppressed(suppressed?: boolean): Promise<void>; public setSuppressed(suppressed?: boolean): Promise<void>;
public getPreview(): Promise<string>; public getPreview(): Promise<string>;