diff --git a/packages/discord.js/src/client/actions/VoiceStateUpdate.js b/packages/discord.js/src/client/actions/VoiceStateUpdate.js index fc7400f2e6ac..1ea9357c42c7 100644 --- a/packages/discord.js/src/client/actions/VoiceStateUpdate.js +++ b/packages/discord.js/src/client/actions/VoiceStateUpdate.js @@ -9,12 +9,6 @@ class VoiceStateUpdate extends Action { const client = this.client; const guild = client.guilds.cache.get(data.guild_id); if (guild) { - // Update the state - const oldState = - guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id }); - - const newState = guild.voiceStates._add(data); - // Get the member let member = guild.members.cache.get(data.user_id); if (member && data.member) { @@ -23,6 +17,15 @@ class VoiceStateUpdate extends Action { member = guild.members._add(data.member); } + // Update the state + const oldState = guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { + user_id: data.user_id, + mute: member._serverMute, + deaf: member._serverDeaf, + }); + + const newState = guild.voiceStates._add(data); + // Emit event if (member?.user.id === client.user.id) { client.emit('debug', `[VOICE] received voice state update: ${JSON.stringify(data)}`); diff --git a/packages/discord.js/src/structures/GuildMember.js b/packages/discord.js/src/structures/GuildMember.js index db71c66b5473..bd166581a5fd 100644 --- a/packages/discord.js/src/structures/GuildMember.js +++ b/packages/discord.js/src/structures/GuildMember.js @@ -62,6 +62,22 @@ class GuildMember extends Base { */ Object.defineProperty(this, '_roles', { value: [], writable: true }); + /** + * The server mute state of the member + * @name GuildMember#_serverMute + * @type {boolean} + * @private + */ + Object.defineProperty(this, '_serverMute', { value: null, writable: true }); + + /** + * The server deaf state of the member + * @name GuildMember#_serverDeaf + * @type {boolean} + * @private + */ + Object.defineProperty(this, '_serverDeaf', { value: null, writable: true }); + if (data) this._patch(data); } @@ -89,6 +105,8 @@ class GuildMember extends Base { this.premiumSinceTimestamp = data.premium_since ? Date.parse(data.premium_since) : null; } if ('roles' in data) this._roles = data.roles; + if ('mute' in data) this._serverMute = data.mute; + if ('deaf' in data) this._serverDeaf = data.deaf; if ('pending' in data) { this.pending = data.pending; @@ -143,7 +161,11 @@ class GuildMember extends Base { * @readonly */ get voice() { - return this.guild.voiceStates.cache.get(this.id) ?? new VoiceState(this.guild, { user_id: this.id }); + return this.guild.voiceStates.cache.get(this.id) ?? new VoiceState(this.guild, { + user_id: this.id, + mute: this._serverMute, + deaf: this._serverDeaf, + }); } /**