feat(Voice): implement support for @discordjs/voice (#5402)

This commit is contained in:
Amish Shah
2021-06-09 14:21:19 +01:00
committed by GitHub
parent c4f1c75efa
commit 7b2e12b102
27 changed files with 99 additions and 2395 deletions

View File

@@ -100,16 +100,6 @@ class VoiceState extends Base {
return this.guild.channels.cache.get(this.channelID) || null;
}
/**
* If this is a voice state of the client user, then this will refer to the active VoiceConnection for this guild
* @type {?VoiceConnection}
* @readonly
*/
get connection() {
if (this.id !== this.client.user.id) return null;
return this.client.voice.connections.get(this.guild.id) || null;
}
/**
* Whether this member is either self-deafened or server-deafened
* @type {?boolean}
@@ -128,16 +118,6 @@ class VoiceState extends Base {
return this.serverMute || this.selfMute;
}
/**
* Whether this member is currently speaking. A boolean if the information is available (aka
* the bot is connected to any voice channel or stage channel in the guild), otherwise this is `null`
* @type {?boolean}
* @readonly
*/
get speaking() {
return this.channel && this.channel.connection ? Boolean(this.channel.connection._speaking.get(this.id)) : null;
}
/**
* Mutes/unmutes the member of this voice state.
* @param {boolean} mute Whether or not the member should be muted
@@ -180,34 +160,6 @@ class VoiceState extends Base {
: Promise.reject(new Error('VOICE_STATE_UNCACHED_MEMBER'));
}
/**
* Self-mutes/unmutes the bot for this voice state.
* @param {boolean} mute Whether or not the bot should be self-muted
* @returns {Promise<boolean>} true if the voice state was successfully updated, otherwise false
*/
async setSelfMute(mute) {
if (this.id !== this.client.user.id) throw new Error('VOICE_STATE_NOT_OWN');
if (typeof mute !== 'boolean') throw new TypeError('VOICE_STATE_INVALID_TYPE', 'mute');
if (!this.connection) return false;
this.selfMute = mute;
await this.connection.sendVoiceStateUpdate();
return true;
}
/**
* Self-deafens/undeafens the bot for this voice state.
* @param {boolean} deaf Whether or not the bot should be self-deafened
* @returns {Promise<boolean>} true if the voice state was successfully updated, otherwise false
*/
async setSelfDeaf(deaf) {
if (this.id !== this.client.user.id) return new Error('VOICE_STATE_NOT_OWN');
if (typeof deaf !== 'boolean') return new TypeError('VOICE_STATE_INVALID_TYPE', 'deaf');
if (!this.connection) return false;
this.selfDeaf = deaf;
await this.connection.sendVoiceStateUpdate();
return true;
}
/**
* Toggles the request to speak in the channel.
* Only applicable for stage channels and for the client's own voice state.