diff --git a/src/handlers/misc/READY.ts b/src/handlers/misc/READY.ts index fb6a6c418..85bc3dbe9 100644 --- a/src/handlers/misc/READY.ts +++ b/src/handlers/misc/READY.ts @@ -5,10 +5,10 @@ import { structures } from "../../structures/mod.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts"; import { DiscordReady } from "../../types/gateway/ready.ts"; import { DiscordGuildMemberWithUser } from "../../types/mod.ts"; -import { camelKeysToSnakeCase, delay } from "../../util/utils.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; import { ws } from "../../ws/ws.ts"; -export async function handleReady( +export function handleReady( data: DiscordGatewayPayload, shardId: number, ) { @@ -40,10 +40,6 @@ export async function handleReady( ); await checkReady(payload, shardId, now); }, 2000); - - // Wait 5 seconds to spawn next shard - await delay(5000); - ws.createNextShard = true; } // Don't pass the shard itself because unavailableGuilds won't be updated by the GUILD_CREATE event diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index d9312cf38..9821ce083 100644 --- a/src/ws/handle_on_message.ts +++ b/src/ws/handle_on_message.ts @@ -4,6 +4,7 @@ import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts"; import { DiscordGatewayPayload } from "../types/gateway/gateway_payload.ts"; import { DiscordHello } from "../types/gateway/hello.ts"; import { DiscordReady } from "../types/gateway/ready.ts"; +import { delay } from "../util/utils.ts"; import { decompressWith } from "./deps.ts"; import { identify } from "./identify.ts"; import { resume } from "./resume.ts"; @@ -96,6 +97,10 @@ export async function handleOnMessage(message: any, shardId: number) { ws.loadingShards.get(shardId)?.resolve(true); ws.loadingShards.delete(shardId); + // Wait 5 seconds to spawn next shard + setTimeout(() => { + ws.createNextShard = true; + }, 5000); } // Update the sequence number if it is present