mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-14 08:08:18 +02:00
correctif load event et commande
This commit is contained in:
+24
-14
@@ -1,19 +1,29 @@
|
|||||||
const { readdirSync } = require("fs");
|
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 totalCommands = loadCommands('../commands');
|
||||||
const dirsCommands = readdirSync("./commands/");
|
console.log(`Commands => ${totalCommands} commandes préfixées chargées sur le bot`);
|
||||||
|
|
||||||
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`);
|
|
||||||
}
|
}
|
||||||
+21
-20
@@ -1,22 +1,23 @@
|
|||||||
const { readdirSync } = require("fs");
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = async client => {
|
module.exports = (client) => {
|
||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const dirsEvents = readdirSync("./events/");
|
const loadEvents = (dir) => {
|
||||||
|
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
||||||
for(const dirs of dirsEvents) {
|
const filePath = path.join(__dirname, dir, file);
|
||||||
const filesDirs = readdirSync(`./events/${dirs}/`).filter(f => f.endsWith(".js"));
|
if (fs.statSync(filePath).isDirectory()) {
|
||||||
for(const files of filesDirs) {
|
loadEvents(path.join(dir, file));
|
||||||
const event = require(`../events/${dirs}/${files}`);
|
} else if (file.endsWith('.js')) {
|
||||||
if(dirs === "music") client.player.events.on(event.name, (...args) => event.run(client, ...args));
|
delete require.cache[require.resolve(filePath)];
|
||||||
else client.on(event.name, (...args) => event.run(client, ...args));
|
const event = require(filePath);
|
||||||
count++;
|
client.on(event.name, (...args) => event.execute(...args, client));
|
||||||
|
console.log(`Event ${event.name} loaded`);
|
||||||
};
|
count++;
|
||||||
|
}
|
||||||
};
|
});
|
||||||
|
}
|
||||||
console.log(`Event => ${count} chargé sur le bot`)
|
loadEvents('../events');
|
||||||
|
console.log(`Event => ${count} chargé sur le bot`)
|
||||||
};
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = async (client) => {
|
|
||||||
const prefixCommandsPath = path.join(__dirname, '../commandprefix'); // Ajustez le chemin ici
|
|
||||||
const commandFiles = fs.readdirSync(prefixCommandsPath).filter(file => file.endsWith('.js'));
|
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
|
||||||
const command = require(`../commandprefix/${file}`); // Ajustez le chemin ici
|
|
||||||
client.prefixCommands.set(command.name, command);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`[Prefix Commands] => ${client.prefixCommands.size} prefix commands loaded`);
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user