import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const rootDir = path.dirname(__dirname); // Load modules function - hot reload functionality removed export const loadModules = async (clientConfig, client) => { const modules = clientConfig.modules || []; const modulesDir = path.join(rootDir, '_opt'); // Create opt directory if it doesn't exist if (!fs.existsSync(modulesDir)) { fs.mkdirSync(modulesDir, { recursive: true }); } // Load each module for (const moduleName of modules) { try { const modulePath = path.join(modulesDir, `${moduleName}.js`); // Check if module exists if (!fs.existsSync(modulePath)) { client.logger.warn(`Module not found: ${modulePath}`); continue; } // Import module (using dynamic import for ES modules) // Import module const moduleUrl = `file://${modulePath}`; const module = await import(moduleUrl); // Register commands if the module has them if (module.commands) { if (Array.isArray(module.commands)) { // Handle array of commands for (const command of module.commands) { if (command.data && typeof command.execute === 'function') { const commandName = command.data.name || command.name; client.commands.set(commandName, command); client.logger.info(`Registered command: ${commandName}`); } } } else if (typeof module.commands === 'object') { // Handle map/object of commands for (const [commandName, command] of Object.entries(module.commands)) { if (command.execute && typeof command.execute === 'function') { client.commands.set(commandName, command); client.logger.info(`Registered command: ${commandName}`); } } } } // Call init function if it exists if (typeof module.init === 'function') { await module.init(client, clientConfig); client.logger.info(`Module loaded: ${moduleName}`); } else { client.logger.info(`Module loaded (no init function): ${moduleName}`); } // Store the module reference (this isn't used for hot reloading anymore) client.modules = client.modules || new Map(); client.modules.set(moduleName, module); } catch (error) { client.logger.error(`Failed to load module ${moduleName}: ${error.message}`); } } };