Skip to content
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

Fix possibly undefined member in voiceStateUpdate #1217

Merged
merged 3 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ declare namespace Eris {
listener: (member: Member, newChannel: AnyVoiceChannel, oldChannel: AnyVoiceChannel) => void
): T;
(event: "voiceStateUpdate", listener: (member: Member, oldState: OldVoiceState) => void): T;
(event: "voiceStateUpdate", listener: (member: UncachedMemberVoiceState, oldState: null) => void): T;
(event: "warn" | "debug", listener: (message: string, id: number) => void): T;
(event: "webhooksUpdate", listener: (data: WebhookData) => void): T;
(event: string, listener: (...args: any[]) => void): T;
Expand Down Expand Up @@ -954,6 +955,10 @@ declare namespace Eris {
}

// Voice
interface UncachedMemberVoiceState {
id: string;
voiceState: OldVoiceState;
}
interface VoiceConnectData {
channel_id: string;
endpoint: string;
Expand Down
18 changes: 16 additions & 2 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,20 @@ class Shard extends EventEmitter {
}
let member = guild.members.get(packet.d.id = packet.d.user_id);
if(!member) {
if(!packet.d.member) {
this.emit("voiceStateUpdate", {
id: packet.d.user_id,
voiceState: {
deaf: packet.d.deaf,
mute: packet.d.mute,
selfDeaf: packet.d.self_deaf,
selfMute: packet.d.self_mute,
selfStream: packet.d.self_stream || false,
selfVideo: packet.d.self_video
}
}, null);
break;
}
// Updates the member cache with this member for future events.
packet.d.member.id = packet.d.user_id;
member = guild.members.add(packet.d.member, guild);
Expand Down Expand Up @@ -795,8 +809,8 @@ class Shard extends EventEmitter {
/**
* Fired when a guild member's voice state changes
* @event Client#voiceStateUpdate
* @prop {Member} member The member
* @prop {Object} oldState The old voice state
* @prop {Member | Object} member The member. If the member is not cached and Discord doesn't send a member payload, this will be an object with `id` and `voiceState` keys. No other property is guaranteed
* @prop {Object?} oldState The old voice state of the member. If the above caveat applies, this will be null
* @prop {Boolean} oldState.deaf The previous server deaf status
* @prop {Boolean} oldState.mute The previous server mute status
* @prop {Boolean} oldState.selfDeaf The previous self deaf status
Expand Down