31 lines
745 B
JavaScript
31 lines
745 B
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function loadEvents(client) {
|
|
const eventsPath = path.join(__dirname, '../events');
|
|
|
|
function walk(dir) {
|
|
const files = fs.readdirSync(dir, { withFileTypes: true });
|
|
|
|
for (const file of files) {
|
|
const filePath = path.join(dir, file.name);
|
|
|
|
if (file.isDirectory()) {
|
|
walk(filePath);
|
|
} else if (file.name.endsWith('.js')) {
|
|
const event = require(filePath);
|
|
|
|
if (event.once) {
|
|
client.once(event.name, (...args) => event.execute(...args, client));
|
|
} else {
|
|
client.on(event.name, (...args) => event.execute(...args, client));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
walk(eventsPath);
|
|
}
|
|
|
|
module.exports = { loadEvents };
|