mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-03 23:36:35 +02:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
module.exports = function loadEvents(client: any, dir: string) {
|
|
let count = 0;
|
|
dir = `../${dir}`
|
|
fs.readdirSync(path.join(__dirname, dir)).forEach((file: string) => {
|
|
const filePath = path.join(__dirname, dir, file);
|
|
if (fs.statSync(filePath).isDirectory()) {
|
|
count += loadCommands(path.join(dir, file));
|
|
} else if (file.endsWith('.js') || file.endsWith('.ts')) {
|
|
try {
|
|
delete require.cache[require.resolve(filePath)];
|
|
const command = require(filePath);
|
|
const fileName = file.replace(/\.js|\.ts/g, '');
|
|
command.name = fileName;
|
|
const parentDir = path.basename(path.dirname(filePath));
|
|
command.category = parentDir === 'commands' ? 'other' : parentDir;
|
|
client.commands.set(fileName, command);
|
|
if (command.aliases) {
|
|
command.aliases.forEach((alias: string) => {
|
|
client.commands.set(alias, command);
|
|
});
|
|
}
|
|
count++;
|
|
} catch (error) {
|
|
console.error(`Failed to load file: ${filePath}`); // Log any errors
|
|
console.error(error);
|
|
}
|
|
}
|
|
});
|
|
return count;
|
|
} |