Added init function to prevent missing env vars
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
const { Client, GatewayIntentBits, Partials, Collection } = require("discord.js")
|
const { Client, GatewayIntentBits, Partials, Collection } = require("discord.js")
|
||||||
const { loadSlashCommandsEvents, loadContextMenuEvents, loadModalEvents, loadButtonEvents, loadEvents, loadAutocompleteEvents } = require("./utils/eventHandler.js")
|
const { loadSlashCommandsEvents, loadContextMenuEvents, loadModalEvents, loadButtonEvents, loadEvents, loadAutocompleteEvents } = require("./utils/eventHandler.js")
|
||||||
const { autoDeployCommands } = require("./utils/autodeploy.js")
|
const { autoDeployCommands } = require("./utils/autodeploy.js")
|
||||||
|
const { init } = require("./utils/init.js")
|
||||||
require("dotenv").config()
|
require("dotenv").config()
|
||||||
const mongoURI = process.env.MONGOURI
|
const mongoURI = process.env.MONGOURI
|
||||||
const { connect } = require("mongoose")
|
const { connect } = require("mongoose")
|
||||||
@@ -26,6 +27,7 @@ client.commands = new Collection()
|
|||||||
client.events = new Collection()
|
client.events = new Collection()
|
||||||
client.modals = new Collection()
|
client.modals = new Collection()
|
||||||
|
|
||||||
|
init()
|
||||||
loadSlashCommandsEvents(client)
|
loadSlashCommandsEvents(client)
|
||||||
loadAutocompleteEvents(client)
|
loadAutocompleteEvents(client)
|
||||||
loadContextMenuEvents(client)
|
loadContextMenuEvents(client)
|
||||||
|
|||||||
38
src/utils/init.js
Normal file
38
src/utils/init.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const envars = [
|
||||||
|
"TOKEN",
|
||||||
|
"MONGOURI",
|
||||||
|
"DEV",
|
||||||
|
"HYPIXELAPIKEY"
|
||||||
|
]
|
||||||
|
const devenvars = [
|
||||||
|
"DEVTOKEN",
|
||||||
|
"CLIENTID",
|
||||||
|
"DEVID",
|
||||||
|
"GUILDID"
|
||||||
|
]
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
if (process.env.NODe_ENV !== "dev") {
|
||||||
|
for (const envar of envars) {
|
||||||
|
if (!process.env[envar]) {
|
||||||
|
console.error(`Missing ${envar} environment variable!`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const envar of envars) {
|
||||||
|
if (!process.env[envar]) {
|
||||||
|
console.error(`Missing ${envar} environment variable!`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const envar of devenvars) {
|
||||||
|
if (!process.env[envar]) {
|
||||||
|
console.error(`Missing ${envar} environment variable!`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { init }
|
||||||
Reference in New Issue
Block a user