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; };