diff --git a/src/module/shard.ts b/src/module/shard.ts index baeff9887..96388a576 100644 --- a/src/module/shard.ts +++ b/src/module/shard.ts @@ -55,12 +55,17 @@ export async function createShard( // TODO: do something about this // TODO(ayntee): check if the readyState of the websocket is OPEN (not sure if this is the solution) - if (!resuming) { - // Intial identify with the gateway - await identify(basicShard, identifyPayload); - } else { - await resume(basicShard, identifyPayload); - } + socket.onopen = async () => { + if (!resuming) { + // Intial identify with the gateway + await identify(basicShard, identifyPayload); + } else { + await resume(basicShard, identifyPayload); + } + }; + + // TODO: handle the WebSocket#error event + socket.onerror = () => {}; socket.onmessage = ({ data: message }) => { if (message instanceof Uint8Array) { diff --git a/test.ts b/test.ts new file mode 100644 index 000000000..ce61c1b50 --- /dev/null +++ b/test.ts @@ -0,0 +1,13 @@ +import { startBot } from "./mod.ts"; +import { Intents } from "./src/types/options.ts"; + +const token = "NzcxMDU2NzQzNTI1Nzc3NDM4.X5mkjQ.KhrhSnfw4fs1VfgRdg0cLxRrDkA"; + +await startBot({ + intents: [Intents.GUILDS, Intents.GUILD_MESSAGES], + token, + eventHandlers: { + ready: () => console.log("hello :)"), + debug: console.log, + }, +});