mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
correctif load event et commande
This commit is contained in:
+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;
|
||||
const dirsEvents = readdirSync("./events/");
|
||||
|
||||
for(const dirs of dirsEvents) {
|
||||
const filesDirs = readdirSync(`./events/${dirs}/`).filter(f => f.endsWith(".js"));
|
||||
for(const files of filesDirs) {
|
||||
const event = require(`../events/${dirs}/${files}`);
|
||||
if(dirs === "music") client.player.events.on(event.name, (...args) => event.run(client, ...args));
|
||||
else client.on(event.name, (...args) => event.run(client, ...args));
|
||||
count++;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
console.log(`Event => ${count} chargé sur le bot`)
|
||||
|
||||
};
|
||||
let count = 0;
|
||||
const loadEvents = (dir) => {
|
||||
fs.readdirSync(path.join(__dirname, dir)).forEach(file => {
|
||||
const filePath = path.join(__dirname, dir, file);
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
loadEvents(path.join(dir, file));
|
||||
} else if (file.endsWith('.js')) {
|
||||
delete require.cache[require.resolve(filePath)];
|
||||
const event = require(filePath);
|
||||
client.on(event.name, (...args) => event.execute(...args, client));
|
||||
console.log(`Event ${event.name} loaded`);
|
||||
count++;
|
||||
}
|
||||
});
|
||||
}
|
||||
loadEvents('../events');
|
||||
console.log(`Event => ${count} chargé sur le bot`)
|
||||
}
|
||||
Reference in New Issue
Block a user