diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..845fa7b --- /dev/null +++ b/commands/help.js @@ -0,0 +1,89 @@ +const { EmbedBuilder, StringSelectMenuBuilder, ActionRowBuilder } = require("discord.js") +/* +module.exports = { + aliases: ['h', 'aide'], + description: 'Affiche la liste des commandes', + emote: '📚', + utilisation: '[commande]', + + async execute(message, args, client) { + console.log("Liste des commandes :"); + let commands = []; + for (const command of client.commands.values()) { + const existingCommand = commands.find(cmd => cmd.name === command.name); + if (!existingCommand) { + commands.push(command); + } + } + console.log(commands); + }, +}; +*/ + + + +module.exports = { + aliases: ['h', 'aide'], + description: 'Affiche la liste des commandes', + emote: '📚', + utilisation: '[commande]', + + async execute(message, args, client) { + const prefix = '+' + if (args[0]) { + const command = client.commands.get(args[0]); + if (!command) { + return message.reply(`Je n'ai pas trouvé de commande nommée "${args[0]}".`); + } + + const commandPerm = 'None' + + const embed_command = new EmbedBuilder() + .setColor('#0099ff') + .setTitle(`Aide pour la commande ${command.emote ? ` ${command.emote}` : '🔧'} ${command.name}`) + .setDescription(command.description) + .addFields( + { name: 'Utilisation', value: `\`${prefix}${command.utilisation ? `${command.utilisation}` : ''}\``, inline: true }, + { name: 'Catégorie', value: command.category || 'Non spécifiée', inline: true }, + { name: 'Alias', value: command.aliases ? command.aliases.map(alias => `\`${alias}\``).join(', ') : 'Aucun', inline: true }, + { name: 'Permissions', value: `Perm level: ${commandPerm}` || 'Indéfini', inline: true }, + ) + .setTimestamp() + .setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})}) + + return message.reply({ embeds: [embed_command] }); + + } else { + + let commands = []; + for (const command of client.commands.values()) { + const existingCommand = commands.find(cmd => cmd.name === command.name); + if (!existingCommand) { + commands.push(command); + } + } + + let categories = {}; + commands.forEach((command) => { + if (!categories[command.category]) { + categories[command.category] = []; + } + categories[command.category].push(command); + }); + + const embed = new EmbedBuilder() + .setTitle('Liste des commandes') + .setDescription('Sélectionnez une catégorie parmi les options ci-dessous pour obtenir de l\'aide sur les commandes correspondantes.') + .setColor('#0099ff'); + + for (const [category, commands] of Object.entries(categories)) { + embed.addFields({ + name: `Catégorie ${category}`, + value: commands.map(command => `\`${command.name}\` - ${command.description}`).join('\n') + }); + } + + message.channel.send({ embeds: [embed] }); + } + }, +}; \ No newline at end of file diff --git a/commands/ping.js b/commands/ping.js index 34dfee3..84d01f8 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -1,7 +1,6 @@ const { ButtonStyle, ButtonBuilder, ActionRowBuilder } = require('discord.js'); module.exports = { - name: 'ping', aliases: ['latence'], description: 'Avoir la latence du bot.', emote: '⏱️', diff --git a/commands/setprefix.js b/commands/setprefix.js index 8327a20..165daff 100644 --- a/commands/setprefix.js +++ b/commands/setprefix.js @@ -3,7 +3,6 @@ const sqlite3 = require('sqlite3').verbose(); require('dotenv').config(); module.exports = { - name: 'setprefix', aliases: ['prefixset'], description: 'Changer le préfixe du bot.', emote: '⏱️', diff --git a/events/messageCreate.js b/events/messageCreate.js index bd7b9ef..c8a9dbb 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -19,7 +19,7 @@ module.exports = { if (permissionLevel < command.permission) return message.reply("Vous n'avez pas la permission d'utiliser cette commande"); try { - command.execute(message, args); + command.execute(message, args, client); } catch (error) { console.error(error); message.reply("Erreur lors de l'exécution de la commande"); diff --git a/fonctions/loadCommands.js b/fonctions/loadCommands.js index 3360ee3..d16972e 100644 --- a/fonctions/loadCommands.js +++ b/fonctions/loadCommands.js @@ -12,7 +12,11 @@ module.exports = function loadEvents(client, dir) { try { delete require.cache[require.resolve(filePath)]; const command = require(filePath); - client.commands.set(command.name, command); + const fileName = file.replace('.js', ''); + command.name = fileName; + const parentDir = path.basename(path.dirname(filePath)); + command.category = parentDir === 'commands' ? 'other' : parentDir; + client.commands.set(fileName, command); if (command.aliases) { command.aliases.forEach(alias => { client.commands.set(alias, command);