UNPKG

@zerospacegg/vynthra

Version:
121 lines (104 loc) 3.77 kB
#!/usr/bin/env node import { createBot, deployCommands } from "../dist/bot/index.js"; import { fileURLToPath } from "url"; import { dirname, join } from "path"; import { readFileSync, existsSync } from "fs"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); function loadConfig() { // Try to load config from environment variables first const token = process.env.DISCORD_TOKEN; const clientId = process.env.DISCORD_CLIENT_ID; const guildId = process.env.DISCORD_GUILD_ID; // Optional if (token && clientId) { return { token, clientId, guildId }; } // Try to load from config file const configPath = join(__dirname, "..", "bot-config.json"); if (existsSync(configPath)) { try { const configFile = readFileSync(configPath, "utf-8"); const config = JSON.parse(configFile); if (!config.token || !config.clientId) { throw new Error("Config file must contain 'token' and 'clientId'"); } return config; } catch (error) { console.error("❌ Error reading config file:", error.message); process.exit(1); } } // No config found console.error("❌ Bot configuration not found!"); console.error(""); console.error( "Please provide Discord bot credentials using one of these methods:", ); console.error(""); console.error("1. Environment variables:"); console.error(" export DISCORD_TOKEN='your_bot_token'"); console.error(" export DISCORD_CLIENT_ID='your_client_id'"); console.error( " export DISCORD_GUILD_ID='your_guild_id' # Optional, for development", ); console.error(""); console.error("2. Create a bot-config.json file:"); console.error(" {"); console.error(' "token": "your_bot_token",'); console.error(' "clientId": "your_client_id",'); console.error(' "guildId": "your_guild_id"'); console.error(" }"); console.error(""); console.error( "Get your bot credentials from: https://discord.com/developers/applications", ); process.exit(1); } async function main() { const args = process.argv.slice(2); const command = args[0] || "start"; // Handle help command without requiring config if (command === "help" || command === "--help" || command === "-h") { console.log("Vynthra Discord Bot"); console.log(""); console.log("Usage: node bin/bot.js <command>"); console.log(""); console.log("Commands:"); console.log(" start Start the Discord bot (default)"); console.log(" deploy Deploy slash commands to Discord"); console.log(" help Show this help message"); console.log(""); console.log("Environment Variables:"); console.log(" DISCORD_TOKEN Your Discord bot token"); console.log(" DISCORD_CLIENT_ID Your Discord application client ID"); console.log(" DISCORD_GUILD_ID Guild ID for development (optional)"); return; } const config = loadConfig(); switch (command) { case "start": console.log("🤖 Starting Vynthra Discord bot..."); console.log(`📋 Client ID: ${config.clientId}`); if (config.guildId) { console.log(`🏠 Guild ID: ${config.guildId} (development mode)`); } else { console.log("🌍 Running in global mode"); } console.log(""); const bot = createBot(config); await bot.start(); break; case "deploy": console.log("🚀 Deploying Discord commands..."); await deployCommands(config); break; default: console.error(`❌ Unknown command: ${command}`); console.error("Run 'node bin/bot.js help' for usage information."); process.exit(1); } } main().catch((error) => { console.error("❌ Fatal error:", error); process.exit(1); });