diff --git a/src/handlers/voice/VOICE_STATE_UPDATE.ts b/src/handlers/voice/VOICE_STATE_UPDATE.ts index 8e2f3b514..31c91ccaa 100644 --- a/src/handlers/voice/VOICE_STATE_UPDATE.ts +++ b/src/handlers/voice/VOICE_STATE_UPDATE.ts @@ -17,6 +17,8 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) { : await cacheHandlers.get("members", snowflakeToBigint(payload.userId)); if (!member) return; + if (!payload.member?.joinedAt) return eventHandlers.lurkerVoiceStateUpdate?.(member, payload); + // No cached state before so lets make one for em const cachedState = guild.voiceStates.get(snowflakeToBigint(payload.userId)); diff --git a/src/types/discordeno/event_handlers.ts b/src/types/discordeno/event_handlers.ts index 60d59545c..e9120f016 100644 --- a/src/types/discordeno/event_handlers.ts +++ b/src/types/discordeno/event_handlers.ts @@ -86,6 +86,8 @@ export type EventHandlersDefinitions = { interactionGuildCreate: [data: Omit, member: DiscordenoMember]; /** Sent when a user uses a Slash Command in a dm (type 2) or clicks a button (type 3). */ interactionDMCreate: [data: Omit]; + /** Sent when a lurker joins/leaves/moves stage channels. */ + lurkerVoiceStateUpdate: [member: DiscordenoMember, voiceState: VoiceState]; /** Sent when a message is created. */ messageCreate: [message: DiscordenoMessage]; /** Sent when a message is deleted. */ diff --git a/tests/ws/start_bot.ts b/tests/ws/start_bot.ts index ec793d1f6..149cadc4c 100644 --- a/tests/ws/start_bot.ts +++ b/tests/ws/start_bot.ts @@ -4,6 +4,7 @@ import { deleteGuild } from "../../src/helpers/guilds/delete_guild.ts"; import { delay } from "../../src/util/utils.ts"; import { ws } from "../../src/ws/ws.ts"; import { assertEquals, assertExists } from "../deps.ts"; +import { delayUntil } from "../util/delay_until.ts"; // Set necessary settings // Disables the logger which logs everything @@ -33,19 +34,17 @@ Deno.test({ const token = Deno.env.get("DISCORD_TOKEN"); if (!token) throw new Error("Token is not provided"); - let didReady = false; - await startBot({ token, - eventHandlers: { - ready: () => (didReady = true), - }, + eventHandlers: {}, intents: ["GuildMessages", "Guilds", "GuildEmojis", "GuildMessageReactions"], }); // Delay the execution by 5 seconds await delay(3000); + await delayUntil(10000, () => cache.isReady); + // DELETE GUILDS IF LESS THAN 10 SERVERS AS SAFETY MEASURE if (cache.guilds.size <= 10) { for (const guild of cache.guilds.values()) await deleteGuild(guild.id); @@ -53,7 +52,7 @@ Deno.test({ // Assertions assertExists(botId); - assertEquals(true, didReady); + assertEquals(true, cache.isReady); }, ...defaultTestOptions, });