fix(bots/discord): check token before connecting to bot api

This commit is contained in:
PalmDevs
2024-04-02 19:31:39 +07:00
parent da21e1a6f7
commit f3e4408aa2

View File

@@ -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()