Skip to content

feat(GuildMember): Expose serverMute and serverDeaf fields #10407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/discord.js/src/client/actions/VoiceStateUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)}`);
Expand Down
24 changes: 23 additions & 1 deletion packages/discord.js/src/structures/GuildMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
});
}

/**
Expand Down
Loading