From f3e4408aa28fb6a9d21365af8c1bea3d07b481de Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Tue, 2 Apr 2024 19:31:39 +0700 Subject: [PATCH] fix(bots/discord): check token before connecting to bot api --- bots/discord/src/index.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/bots/discord/src/index.ts b/bots/discord/src/index.ts index ea4a601..a5a2026 100644 --- a/bots/discord/src/index.ts +++ b/bots/discord/src/index.ts @@ -3,19 +3,6 @@ import { getMissingEnvironmentVariables } from '@revanced/bot-shared' import { api, discord, logger } from './context' import { listAllFilesRecursive, pathJoinCurrentDir } from './utils/fs' -for (const event of listAllFilesRecursive(pathJoinCurrentDir(import.meta.url, 'events', 'api'))) { - await import(event) -} - -const { client: apiClient } = api -await apiClient.ws.connect() - -for (const event of listAllFilesRecursive(pathJoinCurrentDir(import.meta.url, 'events', 'discord'))) { - await import(event) -} - -const { client: discordClient } = discord - // Check if token exists const missingEnvs = getMissingEnvironmentVariables(['DISCORD_TOKEN']) if (missingEnvs.length) { @@ -23,4 +10,14 @@ if (missingEnvs.length) { process.exit(1) } -await discordClient.login() +for (const event of listAllFilesRecursive(pathJoinCurrentDir(import.meta.url, 'events', 'api'))) { + await import(event) +} + +await api.client.connect() + +for (const event of listAllFilesRecursive(pathJoinCurrentDir(import.meta.url, 'events', 'discord'))) { + await import(event) +} + +await discord.client.login()