From 804de4d5f03769c105c2383cee35cd19f626e840 Mon Sep 17 00:00:00 2001 From: VALOU3336 Date: Tue, 13 Feb 2024 21:45:11 +0100 Subject: [PATCH] loader add --- events/client/interactionCreate.js | 14 ++++++++++++++ events/client/ready.js | 11 +++++++++++ loaders/loadCommands.js | 19 +++++++++++++++++++ loaders/loadEvents.js | 22 ++++++++++++++++++++++ loaders/loadPrefixCommands.js | 14 ++++++++++++++ main.js | 8 -------- 6 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 events/client/interactionCreate.js create mode 100644 events/client/ready.js create mode 100644 loaders/loadCommands.js create mode 100644 loaders/loadEvents.js create mode 100644 loaders/loadPrefixCommands.js diff --git a/events/client/interactionCreate.js b/events/client/interactionCreate.js new file mode 100644 index 0000000..b320668 --- /dev/null +++ b/events/client/interactionCreate.js @@ -0,0 +1,14 @@ +const { Events, InteractionType } = require("discord.js") + +module.exports = { + + name :Events.InteractionCreate, + async run(client, interaction) { + + if(interaction.type === InteractionType.ApplicationCommand) { + + const command = client.commands.get(interaction.commandName); + await command.execute(interaction, client); + }; + } +}; \ No newline at end of file diff --git a/events/client/ready.js b/events/client/ready.js new file mode 100644 index 0000000..12db22c --- /dev/null +++ b/events/client/ready.js @@ -0,0 +1,11 @@ +const { Events, ActivityType } = require("discord.js") +module.exports = { + + name : Events.ClientReady, + async run(client) { + + client.application.commands.set(client.commands.map(command => command.data)); + console.log(`${client.user.username} est en ligne`); + + }, +}; \ No newline at end of file diff --git a/loaders/loadCommands.js b/loaders/loadCommands.js new file mode 100644 index 0000000..5b63695 --- /dev/null +++ b/loaders/loadCommands.js @@ -0,0 +1,19 @@ +const { readdirSync } = require("fs"); + + +module.exports = async client => { + + let count = 0; + const dirsCommands = readdirSync("./commands/"); + + for(const dirs of dirsCommands) { + const filesDirs = readdirSync(`./commands/${dirs}/`).filter(f => f.endsWith(".js")); + for(const files of filesDirs) { + const command = require(`../commands/${dirs}/${files}`); + client.commands.set(command.data.name, command); + count++; + } + }; + + console.log(`[Commands Slash] => ${count} logged commands`); +} \ No newline at end of file diff --git a/loaders/loadEvents.js b/loaders/loadEvents.js new file mode 100644 index 0000000..88647cd --- /dev/null +++ b/loaders/loadEvents.js @@ -0,0 +1,22 @@ +const { readdirSync } = require("fs"); + +module.exports = async client => { + + let count = 0; + const dirsEvents = readdirSync("./events/"); + + for(const dirs of dirsEvents) { + const filesDirs = readdirSync(`./events/${dirs}/`).filter(f => f.endsWith(".js")); + for(const files of filesDirs) { + const event = require(`../events/${dirs}/${files}`); + if(dirs === "music") client.player.events.on(event.name, (...args) => event.run(client, ...args)); + else client.on(event.name, (...args) => event.run(client, ...args)); + count++; + + }; + + }; + + console.log(`Event => ${count} chargé sur le bot`) + +}; \ No newline at end of file diff --git a/loaders/loadPrefixCommands.js b/loaders/loadPrefixCommands.js new file mode 100644 index 0000000..b91728f --- /dev/null +++ b/loaders/loadPrefixCommands.js @@ -0,0 +1,14 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = async (client) => { + const prefixCommandsPath = path.join(__dirname, '../commandprefix'); // Ajustez le chemin ici + const commandFiles = fs.readdirSync(prefixCommandsPath).filter(file => file.endsWith('.js')); + + for (const file of commandFiles) { + const command = require(`../commandprefix/${file}`); // Ajustez le chemin ici + client.prefixCommands.set(command.name, command); + } + + console.log(`[Prefix Commands] => ${client.prefixCommands.size} prefix commands loaded`); +}; \ No newline at end of file diff --git a/main.js b/main.js index df8a6dc..f8b84b4 100644 --- a/main.js +++ b/main.js @@ -7,12 +7,4 @@ client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); -client.on('interactionCreate', async interaction => { - if (!interaction.isChatInputCommand()) return; - - if (interaction.commandName === 'ping') { - await interaction.reply('Pong!'); - } -}); - client.login(process.env.TOKEN); \ No newline at end of file