From ea193cedddc0345deb0c001e71fa649addac397a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 18 Jun 2022 01:06:38 +0200 Subject: [PATCH] Event folder --- src/events/ready.js | 7 +++++++ src/index.js | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/events/ready.js diff --git a/src/events/ready.js b/src/events/ready.js new file mode 100644 index 0000000..c658849 --- /dev/null +++ b/src/events/ready.js @@ -0,0 +1,7 @@ +module.exports = { + name: 'ready', + once: true, + execute() { + console.log('PrĂȘt !'); + }, +}; diff --git a/src/index.js b/src/index.js index 1629501..72fd311 100644 --- a/src/index.js +++ b/src/index.js @@ -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);