diff --git a/commands/ping.js b/commands/ping.js new file mode 100644 index 0000000..1aa7e82 --- /dev/null +++ b/commands/ping.js @@ -0,0 +1,14 @@ +const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js'); + +module.exports = { + name: 'ping', + aliases: ['latence'], + description: 'Avoir la latence du bot.', + emote: '⏱️', + utilisation: 'ping', + category: 'utils', + + async execute(message, args, client) { + message.reply('Pong !'); + }, +}; \ No newline at end of file diff --git a/events/messageCreate.js b/events/messageCreate.js new file mode 100644 index 0000000..fc15019 --- /dev/null +++ b/events/messageCreate.js @@ -0,0 +1,24 @@ +const { Events } = require("discord.js"); + +module.exports = { + name: Events.MessageCreate, + async execute(message, client) { + const prefix = "+"; + + if (message.author.bot) return; + if (!message.content.startsWith(prefix)) return; + + const args = message.content.slice(prefix.length).trim().split(/ +/); + const commandName = args.shift().toLowerCase(); + + const command = client.commands.get(commandName); + if (!command) return; + + try { + command.execute(message, args); + } catch (error) { + console.error(error); + message.reply("Erreur lors de l'exécution de la commande"); + } + } +}; \ No newline at end of file diff --git a/events/ready.js b/events/ready.js new file mode 100644 index 0000000..b7332ec --- /dev/null +++ b/events/ready.js @@ -0,0 +1,8 @@ +const { Events, ActivityType } = require("discord.js"); + +module.exports = { + name: Events.ClientReady, + async execute(client) { + console.log(`le bot ${client.user.tag} est en ligne`) + } +}; \ No newline at end of file diff --git a/fonctions/loadCommands.js b/fonctions/loadCommands.js new file mode 100644 index 0000000..3360ee3 --- /dev/null +++ b/fonctions/loadCommands.js @@ -0,0 +1,29 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function loadEvents(client, dir) { + let count = 0; + dir = `../${dir}` + fs.readdirSync(path.join(__dirname, dir)).forEach(file => { + const filePath = path.join(__dirname, dir, file); + if (fs.statSync(filePath).isDirectory()) { + count += loadCommands(path.join(dir, file)); + } else if (file.endsWith('.js')) { + try { + delete require.cache[require.resolve(filePath)]; + const command = require(filePath); + client.commands.set(command.name, command); + if (command.aliases) { + command.aliases.forEach(alias => { + client.commands.set(alias, command); + }); + } + count++; + } catch (error) { + console.error(`Failed to load file: ${filePath}`); // Log any errors + console.error(error); + } + } + }); + return count; +} \ No newline at end of file diff --git a/fonctions/loadEvents.js b/fonctions/loadEvents.js new file mode 100644 index 0000000..ae529f5 --- /dev/null +++ b/fonctions/loadEvents.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function loadEvents(client, dir) { + let count = 0; + dir = `../${dir}` + fs.readdirSync(path.join(__dirname, dir)).forEach(file => { + const filePath = path.join(__dirname, dir, file); + if (fs.statSync(filePath).isDirectory()) { + loadEvents(path.join(dir, file)); + } else if (file.endsWith('.js')) { + delete require.cache[require.resolve(filePath)]; + const event = require(filePath); + if (typeof event.execute === 'function') { + client.on(event.name, (...args) => event.execute(...args, client)); + count++; + } else { + console.error(`Event ${event.name} does not have an execute method.`); + } + } + }); + return count; +} \ No newline at end of file diff --git a/fonctions/run.js b/fonctions/run.js new file mode 100644 index 0000000..5275ba6 --- /dev/null +++ b/fonctions/run.js @@ -0,0 +1,15 @@ +const { Client, IntentsBitField, Collection } = require('discord.js') +const loadEvents = require("./loadEvents"); +const loadCommands = require("./loadCommands"); + +module.exports = function run(token) { + const client = new Client({intents: new IntentsBitField(3276799)}); + + client.events = new Collection(); + client.commands = new Collection(); + + console.log(`${loadEvents(client, 'events')} events loaded`); + console.log(`${loadCommands(client, 'commands')} commands loaded`); + + client.login(token); +} \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..9d853cd --- /dev/null +++ b/main.js @@ -0,0 +1,9 @@ +require('dotenv').config() +const run = require("./fonctions/run"); +tokens = process.env.TOKENS.split(',') + +const runAsync = async () => { + Promise.all(tokens.map(token => run(token))); +}; + +runAsync(); \ No newline at end of file