add fonctions

This commit is contained in:
Arthur
2024-05-26 19:53:29 +02:00
committed by GitHub
parent b1b9c3d8a9
commit a0f70467a5
4 changed files with 144 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
const fs = require('fs');
const path = require('path');
module.exports = function loadCommands(client, dir) {
let count = 0;
fs.readdirSync(path.join(__dirname, dir)).forEach((file) => {
const filePath = path.join(__dirname, dir, file);
if (fs.statSync(filePath).isDirectory()) {
count += loadCommands(client, 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, '');
if (!command.name) command.name = fileName;
if (!command.category) {
const parentDir = path.basename(path.dirname(filePath));
command.category = parentDir === 'commands' ? 'other' : parentDir;
}
if (!command.permission) command.permission = 0;
client.commands.set(fileName, command);
if (command.aliases) {
command.aliases.forEach((alias) => {
client.commands.set(alias, command);
});
}
count++;
} catch (error) {
console.error(`Failed to load file: ${filePath}`);
console.error(error);
}
}
});
return count;
}