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
+22
View File
@@ -0,0 +1,22 @@
const fs = require('fs');
const path = require('path');
module.exports = function loadEvents(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()) {
loadEvents(client, path.join(dir, file));
} else if (file.endsWith('.js') || file.endsWith('.ts')) {
delete require.cache[require.resolve(filePath)];
const event = require(filePath);
if (typeof event.execute === 'function') {
client.on(event.name, (...args) => event.execute(...args, client)); // Specify the type of 'args' as an array of any type
count++;
} else {
console.error(`Event ${event.name} does not have an execute method.`);
}
}
});
return count;
}