fix: handle undef Guild#voiceStates

This commit is contained in:
ayntee
2020-12-30 13:18:02 +04:00
parent f3b0006327
commit ddd3c32e21
2 changed files with 5 additions and 5 deletions

View File

@@ -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;

View File

@@ -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);
}
}