mirror of
https://github.com/arthur-pbty/gestion-perso.git
synced 2026-06-03 23:36:35 +02:00
29 lines
897 B
JavaScript
29 lines
897 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
module.exports = function loadEvents(client, dir) {
|
|
let count = 0;
|
|
dir = `../${dir}`
|
|
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
|
const filePath = path.join(__dirname, dir, file);
|
|
if (fs.statSync(filePath).isDirectory()) {
|
|
count += loadCommands(path.join(dir, file));
|
|
} else if (file.endsWith('.js')) {
|
|
try {
|
|
delete require.cache[require.resolve(filePath)];
|
|
const command = require(filePath);
|
|
client.commands.set(command.name, command);
|
|
if (command.aliases) {
|
|
command.aliases.forEach(alias => {
|
|
client.commands.set(alias, command);
|
|
});
|
|
}
|
|
count++;
|
|
} catch (error) {
|
|
console.error(`Failed to load file: ${filePath}`); // Log any errors
|
|
console.error(error);
|
|
}
|
|
}
|
|
});
|
|
return count;
|
|
} |