Skip to content

Commit

Permalink
fix(Member): fix updating from voice state updates (#131)
Browse files Browse the repository at this point in the history
* fix(Member): fix updating from voice state updates

* fix(Member): update user along with member update

* nit: reword the comment above

---------

Co-authored-by: TTtie <[email protected]>
  • Loading branch information
Snazzah and TTtie authored Apr 27, 2024
1 parent 0249cf1 commit 1c3db75
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/structures/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ class Member extends Base {
}

update(data) {
// Handle updates from voice states
if(data.hasOwnProperty("member") && data.hasOwnProperty("channel_id") && this.guild) {
const state = this.guild.voiceStates.get(this.id);
if(data.channel_id === null && !data.mute && !data.deaf && !data.suppress) {
this.guild.voiceStates.delete(this.id);
} else if(state) {
state.update(data);
} else if(data.channel_id || data.mute || data.deaf || data.suppress) {
this.guild.voiceStates.update(data);
}
data = data.member;
}

if(data.status !== undefined) {
/**
* The member's status. Either "online", "idle", "dnd", or "offline"
Expand Down Expand Up @@ -99,16 +112,6 @@ class Member extends Base {
*/
this.premiumSince = data.premium_since === null ? null : Date.parse(data.premium_since);
}
if(data.hasOwnProperty("mute") && this.guild) {
const state = this.guild.voiceStates.get(this.id);
if(data.channel_id === null && !data.mute && !data.deaf && !data.suppress) {
this.guild.voiceStates.delete(this.id);
} else if(state) {
state.update(data);
} else if(data.channel_id || data.mute || data.deaf || data.suppress) {
this.guild.voiceStates.update(data);
}
}
if(data.nick !== undefined) {
this.nick = data.nick;
}
Expand Down Expand Up @@ -143,6 +146,9 @@ class Member extends Base {
if(data.flags !== undefined) {
this.flags = data.flags;
}
if(data.user !== undefined) {
this.user.update(data.user);
}
}

/**
Expand Down

0 comments on commit 1c3db75

Please sign in to comment.