forked from noxious/server
Uhm excuse me, but what the fuck
This commit is contained in:
@ -61,43 +61,34 @@ class CommandManager {
|
||||
}
|
||||
|
||||
private async loadCommands() {
|
||||
const commandsDir = path.join(process.cwd(), 'src', 'commands')
|
||||
const commandsDir = path.join(process.cwd(), 'src', 'commands');
|
||||
commandLogger.info(`Loading commands from: ${commandsDir}`);
|
||||
|
||||
try {
|
||||
const files: string[] = await fs.promises.readdir(commandsDir)
|
||||
const files = await fs.promises.readdir(commandsDir, { withFileTypes: true });
|
||||
|
||||
for (const file of files) {
|
||||
if (!file.isFile() || (!file.name.endsWith('.ts') && !file.name.endsWith('.js'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const fullPath = path.join(commandsDir, file.name);
|
||||
const commandName = path.basename(file.name, path.extname(file.name));
|
||||
|
||||
try {
|
||||
const extension = path.extname(file)
|
||||
const commandName = path.basename(file, extension)
|
||||
|
||||
let commandPath: string
|
||||
commandPath = path.join(commandsDir, `${commandName}.js`)
|
||||
|
||||
if (config.ENV === 'development') {
|
||||
commandPath = path.join(commandsDir, `${commandName}.ts`)
|
||||
const module = await import(fullPath);
|
||||
if (typeof module.default !== 'function') {
|
||||
commandLogger.warn(`Unrecognized export in ${file.name}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(commandPath)) {
|
||||
commandLogger.warn(`Command file not found: ${commandPath}`)
|
||||
continue
|
||||
}
|
||||
|
||||
// Use dynamic import
|
||||
const CommandModule = await import(commandPath)
|
||||
const CommandClass = CommandModule.default
|
||||
|
||||
if (!CommandClass || typeof CommandClass !== 'function') {
|
||||
commandLogger.warn(`Invalid command class in file: ${commandPath}`)
|
||||
continue
|
||||
}
|
||||
|
||||
this.registerCommand(commandName, CommandClass)
|
||||
this.registerCommand(commandName, module.default);
|
||||
} catch (error) {
|
||||
commandLogger.error(`Failed to load command: ${file}: ${error}`)
|
||||
commandLogger.error(`Error loading command ${file.name}: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
commandLogger.error(`Failed to read commands directory: ${error}`)
|
||||
commandLogger.error(`Failed to read commands directory: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user