Ignore events if the directory is not there or if it is empty

This commit is contained in:
Logan Cusano
2023-03-26 15:24:17 -04:00
parent eebd058eae
commit 444346e2b5

View File

@@ -125,16 +125,19 @@ discordClient.on('ready', () => {
// Setup any additional event handlers
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
discordClient.once(event.name, (...args) => event.execute(...args));
} else {
discordClient.on(event.name, (...args) => event.execute(...args));
}
if (fs.existsSync(eventsPath)) {
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
if (eventFiles.length > 0) {
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
discordClient.once(event.name, (...args) => event.execute(...args));
} else {
discordClient.on(event.name, (...args) => event.execute(...args));
}
}
}
}
discordClient.login(discordToken); //Load Client Discord Token