Kord/src/handlers/CommandLoader.ts

23 lines
855 B
TypeScript

import { KordClient } from '../client/KordClient';
import { logger } from '../utils/logger';
import fs from 'fs';
import path from 'path';
export const loadCommands = async (client: KordClient) => {
const commandsPath = path.join(__dirname, '../commands');
if (!fs.existsSync(commandsPath)) return;
const commandFiles = fs.readdirSync(commandsPath).filter(f => f.endsWith('.ts') || f.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath).default;
if (command && 'data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
logger.debug(`Loaded command: ${command.data.name}`);
} else {
logger.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
};