correctif load event et commande

This commit is contained in:
VALOU3336
2024-02-13 21:50:33 +01:00
parent 804de4d5f0
commit e9ad8e6409
3 changed files with 45 additions and 48 deletions
+24 -14
View File
@@ -1,19 +1,29 @@
const { readdirSync } = require("fs");
module.exports = async client => {
module.exports = (client) => {
const loadCommands = (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(path.join(dir, file));
} else if (file.endsWith('.js')) {
try {
// Delete the cache for this command file
delete require.cache[require.resolve(filePath)];
const command = require(filePath);
client.commands.set(command.name, command);
count++;
} catch (error) {
console.error(`Failed to load file: ${filePath}`); // Log any errors
console.error(error);
}
}
});
return count;
}
let count = 0;
const dirsCommands = readdirSync("./commands/");
for(const dirs of dirsCommands) {
const filesDirs = readdirSync(`./commands/${dirs}/`).filter(f => f.endsWith(".js"));
for(const files of filesDirs) {
const command = require(`../commands/${dirs}/${files}`);
client.commands.set(command.data.name, command);
count++;
}
};
console.log(`[Commands Slash] => ${count} logged commands`);
const totalCommands = loadCommands('../commands');
console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot`);
}