From ad8f872cfcefb3a4da050ea2d0afd222be3c7005 Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 5 Jun 2021 02:04:58 +0100 Subject: [PATCH 1/3] Fix possibly undefined member in voiceStateUpdate --- index.d.ts | 5 +++++ lib/gateway/Shard.js | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index aec9f5dcc..62153073c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; @@ -954,6 +955,10 @@ declare namespace Eris { } // Voice + interface UncachedMemberVoiceState { + id: string; + voiceState: OldVoiceState; + } interface VoiceConnectData { channel_id: string; endpoint: string; diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index df4710d5c..1267eba15 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -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.selfStream || 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); @@ -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 If 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 From ff47d0bf16716daea8a0990fb73ece0ebc6d4242 Mon Sep 17 00:00:00 2001 From: bsian03 Date: Fri, 2 Jul 2021 23:41:57 +0100 Subject: [PATCH 2/3] Update lib/gateway/Shard.js Co-authored-by: Erin --- lib/gateway/Shard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 1267eba15..2c529814f 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -810,7 +810,7 @@ class Shard extends EventEmitter { * Fired when a guild member's voice state changes * @event Client#voiceStateUpdate * @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 If the member. If the above caveat applies, this will be null + * @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 From d6df66852d4e0904010fb5ddd50e38374332cb5a Mon Sep 17 00:00:00 2001 From: bsian03 Date: Fri, 2 Jul 2021 23:43:55 +0100 Subject: [PATCH 3/3] fix typo --- lib/gateway/Shard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 2c529814f..6f41497ef 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -739,7 +739,7 @@ class Shard extends EventEmitter { mute: packet.d.mute, selfDeaf: packet.d.self_deaf, selfMute: packet.d.self_mute, - selfStream: packet.d.selfStream || false, + selfStream: packet.d.self_stream || false, selfVideo: packet.d.self_video } }, null);