woomy/modules/events.js
2020-04-04 01:55:35 +11:00

21 lines
606 B
JavaScript

const fs = require('fs')
module.exports = client => {
fs.readdir('./events', (err, files) => {
if (err) {
client.logger.fatal('Failed to get files in events directory: ' + err)
process.exit()
}
client.logger.info(`Loading ${files.length} events.`)
files.forEach(file => {
if (!file.endsWith('.js')) {
return
}
try {
const event = require(`../events/${file}`)
client.on(file.substr(0, file.length - 3), event.bind(null, client))
} catch (err) {
client.logger.error(`Failed to load ${file}: ${err}`)
}
})
})
}