Add environment variable validation to bot.js
cgen-65cdc8ed704240e68cf47c612775b9eb
This commit is contained in:
parent
2b4c4acd3d
commit
ce4a36fcde
1 changed files with 21 additions and 0 deletions
|
|
@ -11,6 +11,27 @@ const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
|
|
||||||
|
// Validate environment variables
|
||||||
|
const requiredEnvVars = [
|
||||||
|
"DISCORD_BOT_TOKEN",
|
||||||
|
"DISCORD_CLIENT_ID",
|
||||||
|
"SUPABASE_URL",
|
||||||
|
"SUPABASE_SERVICE_ROLE",
|
||||||
|
];
|
||||||
|
|
||||||
|
const missingVars = requiredEnvVars.filter((envVar) => !process.env[envVar]);
|
||||||
|
if (missingVars.length > 0) {
|
||||||
|
console.error(
|
||||||
|
"❌ FATAL ERROR: Missing required environment variables:",
|
||||||
|
missingVars.join(", ")
|
||||||
|
);
|
||||||
|
console.error("\nPlease set these in your Discloud/hosting environment:");
|
||||||
|
missingVars.forEach((envVar) => {
|
||||||
|
console.error(` - ${envVar}`);
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize Discord client
|
// Initialize Discord client
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.DirectMessages],
|
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.DirectMessages],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue