mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-18 00:33:59 +00:00
fix(bots/discord): check token before connecting to bot api
This commit is contained in:
@@ -3,19 +3,6 @@ import { getMissingEnvironmentVariables } from '@revanced/bot-shared'
|
|||||||
import { api, discord, logger } from './context'
|
import { api, discord, logger } from './context'
|
||||||
import { listAllFilesRecursive, pathJoinCurrentDir } from './utils/fs'
|
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
|
// Check if token exists
|
||||||
const missingEnvs = getMissingEnvironmentVariables(['DISCORD_TOKEN'])
|
const missingEnvs = getMissingEnvironmentVariables(['DISCORD_TOKEN'])
|
||||||
if (missingEnvs.length) {
|
if (missingEnvs.length) {
|
||||||
@@ -23,4 +10,14 @@ if (missingEnvs.length) {
|
|||||||
process.exit(1)
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user