update
This commit is contained in:
@@ -86,11 +86,15 @@ class VoiceState extends Base {
|
||||
|
||||
// The self_stream is property is omitted if false, check for another property
|
||||
// here to avoid incorrectly clearing this when partial data is specified
|
||||
/**
|
||||
* Whether this member is streaming using "Screen Share"
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.streaming = data.self_stream ?? false;
|
||||
if ('self_stream' in data) {
|
||||
/**
|
||||
* Whether this member is streaming using "Screen Share"
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.streaming = data.self_stream ?? false;
|
||||
} else {
|
||||
this.streaming ??= null;
|
||||
}
|
||||
|
||||
if ('channel_id' in data) {
|
||||
/**
|
||||
@@ -144,12 +148,11 @@ class VoiceState extends Base {
|
||||
|
||||
/**
|
||||
* The channel that the member is connected to
|
||||
* @type {?(VoiceChannel|StageChannel)}
|
||||
* @type {?(VoiceChannel|StageChannel|DMChannel|GroupDMChannel)}
|
||||
* @readonly
|
||||
*/
|
||||
get channel() {
|
||||
if (!this.guild?.id) return this.guild.client.channels.cache.get(this.channelId) ?? null;
|
||||
return this.guild.channels.cache.get(this.channelId) ?? null;
|
||||
return (this.guild || this.client).channels.cache.get(this.channelId) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +180,6 @@ class VoiceState extends Base {
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
setMute(mute = true, reason) {
|
||||
if (!this.guild?.id) return null;
|
||||
return this.guild.members.edit(this.id, { mute }, reason);
|
||||
}
|
||||
|
||||
@@ -188,7 +190,6 @@ class VoiceState extends Base {
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
setDeaf(deaf = true, reason) {
|
||||
if (!this.guild?.id) return null;
|
||||
return this.guild.members.edit(this.id, { deaf }, reason);
|
||||
}
|
||||
|
||||
@@ -198,7 +199,6 @@ class VoiceState extends Base {
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
disconnect(reason) {
|
||||
if (!this.guild?.id) return this.callVoice?.disconnect();
|
||||
return this.setChannel(null, reason);
|
||||
}
|
||||
|
||||
@@ -210,36 +210,9 @@ class VoiceState extends Base {
|
||||
* @returns {Promise<GuildMember>}
|
||||
*/
|
||||
setChannel(channel, reason) {
|
||||
if (!this.guild?.id) return null;
|
||||
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.
|
||||
* Only applicable for stage channels and for the client's own voice state.
|
||||
@@ -253,18 +226,16 @@ class VoiceState extends Base {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async setRequestToSpeak(request = true) {
|
||||
if (this.guild?.id) {
|
||||
if (this.channel?.type !== 'GUILD_STAGE_VOICE') throw new Error('VOICE_NOT_STAGE_CHANNEL');
|
||||
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');
|
||||
if (this.client.user.id !== this.id) throw new Error('VOICE_STATE_NOT_OWN');
|
||||
|
||||
await this.client.api.guilds(this.guild.id, 'voice-states', '@me').patch({
|
||||
data: {
|
||||
channel_id: this.channelId,
|
||||
request_to_speak_timestamp: request ? new Date().toISOString() : null,
|
||||
},
|
||||
});
|
||||
}
|
||||
await this.client.api.guilds(this.guild.id, 'voice-states', '@me').patch({
|
||||
data: {
|
||||
channel_id: this.channelId,
|
||||
request_to_speak_timestamp: request ? new Date().toISOString() : null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,21 +256,39 @@ class VoiceState extends Base {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async setSuppressed(suppressed = true) {
|
||||
if (this.guild?.id) {
|
||||
if (typeof suppressed !== 'boolean') throw new TypeError('VOICE_STATE_INVALID_TYPE', 'suppressed');
|
||||
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');
|
||||
if (this.channel?.type !== 'GUILD_STAGE_VOICE') throw new Error('VOICE_NOT_STAGE_CHANNEL');
|
||||
|
||||
const target = this.client.user.id === this.id ? '@me' : this.id;
|
||||
const target = this.client.user.id === this.id ? '@me' : this.id;
|
||||
|
||||
await this.client.api.guilds(this.guild.id, 'voice-states', target).patch({
|
||||
data: {
|
||||
channel_id: this.channelId,
|
||||
suppress: suppressed,
|
||||
request_to_speak_timestamp: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
await this.client.api.guilds(this.guild.id, 'voice-states', target).patch({
|
||||
data: {
|
||||
channel_id: this.channelId,
|
||||
suppress: suppressed,
|
||||
request_to_speak_timestamp: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>}
|
||||
*/
|
||||
setStatus(status = '') {
|
||||
// PUT https://discord.com/api/v9/channels/:id/voice-status
|
||||
return this.client.api.channels(this.channel.id, 'voice-status').put({
|
||||
data: {
|
||||
status,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,19 +311,18 @@ class VoiceState extends Base {
|
||||
* @param {string} base64Image Base64 URI (data:image/jpeg;base64,data)
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async postPreview(base64Image) {
|
||||
postPreview(base64Image) {
|
||||
if (!this.client.user.id === this.id || !this.streaming) throw new Error('USER_NOT_STREAMING');
|
||||
// URL: https://discord.com/api/v9/streams/guild:guildid:voicechannelid:userid/preview
|
||||
// URL: https://discord.com/api/v9/streams/call:channelId:userId/preview
|
||||
const streamKey = this.guild.id
|
||||
? `guild:${this.guild.id}:${this.channelId}:${this.id}`
|
||||
: `call:${this.channelId}:${this.id}`;
|
||||
await this.client.api.streams[encodeURIComponent(streamKey)].preview.post({
|
||||
return this.client.api.streams[encodeURIComponent(streamKey)].preview.post({
|
||||
data: {
|
||||
thumbnail: base64Image,
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
||||
Reference in New Issue
Block a user