Split into multiple files #18

Merged
Anri merged 22 commits from dev into main 2022-07-03 18:43:31 +02:00
2 changed files with 21 additions and 3 deletions
Showing only changes of commit ea193ceddd - Show all commits

7
src/events/ready.js Normal file
View file

@ -0,0 +1,7 @@
module.exports = {
name: 'ready',
once: true,
execute() {
console.log('Prêt !');
},
};

View file

@ -1,10 +1,21 @@
const fs = require('node:fs');
const path = require('node:path');
const { Client, Intents } = require('discord.js');
const { token } = require('../config/config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Prêt !');
});
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) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.login(token);