diff --git a/src/ws/handle_on_message.ts b/src/ws/handle_on_message.ts index 9cd09145a..00246625f 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"; @@ -66,6 +67,9 @@ export async function handleOnMessage(message: any, shardId: number) { case DiscordGatewayOpcodes.InvalidSession: ws.log("INVALID_SESSION", { shardId, payload: messageData }); + // We need to wait for a random amount of time between 1 and 5 + await delay(Math.floor((Math.random() * 4 + 1) * 1000)); + // When d is false we need to reidentify if (!messageData.d) { await identify(shardId, ws.maxShards);