diff --git a/src/api/controllers/channels.ts b/src/api/controllers/channels.ts index 86c00fe87..34607aeea 100644 --- a/src/api/controllers/channels.ts +++ b/src/api/controllers/channels.ts @@ -28,12 +28,12 @@ export async function handleInternalChannelDelete(data: DiscordPayload) { if (cachedChannel.type === ChannelTypes.GUILD_VOICE && payload.guild_id) { const guild = await cacheHandlers.get("guilds", payload.guild_id); - if (guild) { + if (guild && guild.voiceStates) { return Promise.all(guild.voiceStates.map(async (vs, key) => { if (vs.channelID !== payload.id) return; // Since this channel was deleted all voice states for this channel should be deleted - guild.voiceStates.delete(key); + guild.voiceStates?.delete(key); const member = await cacheHandlers.get("members", vs.userID); if (!member) return; diff --git a/src/api/controllers/misc.ts b/src/api/controllers/misc.ts index 3992c099b..b5a7fbca9 100644 --- a/src/api/controllers/misc.ts +++ b/src/api/controllers/misc.ts @@ -97,9 +97,9 @@ export async function handleInternalVoiceStateUpdate(data: DiscordPayload) { if (!member) return; // No cached state before so lets make one for em - const cachedState = guild.voiceStates.get(payload.user_id); + const cachedState = guild.voiceStates?.get(payload.user_id); - guild.voiceStates.set(payload.user_id, { + guild.voiceStates?.set(payload.user_id, { ...payload, guildID: payload.guild_id, channelID: payload.channel_id || "", @@ -124,7 +124,7 @@ export async function handleInternalVoiceStateUpdate(data: DiscordPayload) { } } // Left the channel else if (cachedState?.channelID) { - guild.voiceStates.delete(payload.user_id); + guild.voiceStates?.delete(payload.user_id); eventHandlers.voiceChannelLeave?.(member, cachedState.channelID); } }