const { EmbedBuilder, StringSelectMenuBuilder, ActionRowBuilder } = require("discord.js") const sqlite3 = require('sqlite3').verbose(); const db = new sqlite3.Database('myDatabase.db'); module.exports = { name: 'help', aliases: ['aide'], description: 'Affiche la liste des commandes', category: 'utils', emote: '📚', utilisation: 'help [commande]', async execute(message, args, client) { const botId = client.user.id; const guildId = message.guild.id; if (args[0] === 'msg' ) { const embed = new EmbedBuilder() .setTitle("Arguments de messages") .addFields( { name: '{MemberMention}', value: `Mentionne le membre concerné` , inline: true }, { name: '{MemberName}', value: `Le nom du membre concerné` , inline: true }, { name: '{MemberDisplayName}', value:'Le pseudo de serveur du membre concerné', inline: true }, { name: '{MemberJoinedAt}',value: `La date à la quelle le membre concerné a rejoint le serveur`, inline: true }, { name: '{MemberID}', value: `L'ID du membre concerné` , inline: true }, { name: '{MemberPic}', value:'La photo de profil du membre concerné' , inline: true }, { name: '{MemberCreatedAt}', value: 'La date de création du compte du membre concerné ', inline: true }, { name: '{ServerName}', value: 'Le nom du serveur concerné', inline: true }, { name: '{ServerMembersCount}', value: 'Le nombre total de membres sur le serveur', inline: true } ) return message.reply({ embeds: [embed] }); } let data = await new Promise((resolve, reject) => { db.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => { if (err) { console.error(err.message); reject(err); } resolve(row ? JSON.parse(row.value) : {}); }); }); const permissions = data.permissions || {}; const defaultPrefix = "+"; let mainPrefix = data.prefixes && data.prefixes.main ? data.prefixes.main : defaultPrefix; let serverPrefix = data.prefixes && data.prefixes[guildId]; const prefix = serverPrefix !== undefined ? serverPrefix : mainPrefix; 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 = await permissions[command.name]; let customAliases = []; if (data.alias && data.alias[command.name]) { customAliases = Object.keys(data.alias[command.name]); } const allAliases = [...(command.aliases || []), ...customAliases]; let aliasesField = { name: 'Alias', value: 'Aucun', inline: true }; if (allAliases.length > 0) { aliasesField.value = allAliases.map(alias => `\`${alias}\``).join(', '); } 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 }, aliasesField, { name: 'Permissions', value: commandPerm === 11 ? 'buyer' : commandPerm === 10 ? 'owner' : `Perm level: ${commandPerm}`, inline: true }, ) .setTimestamp() .setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})}) return message.reply({ embeds: [embed_command] }); } const categories = { antiraid: [], botcontrol: [], moderation: [], buyer: [], game: [], gestion: [], utils: [], other: [], }; let liste = []; for (const command of client.commands.values()) { const existingCommand = liste.find(cmd => cmd.name === command.name); if (!existingCommand) { liste.push(command); } } for (const command of liste) { if (command.category && categories[command.category]) { categories[command.category].push({ name: command.name, description: command.description, emote: command.emote, utilisation: command.utilisation}); } else { categories['other'].push({ name: command.name, description: command.description, emote: command.emote, utilisation: command.utilisation}); } } let totalCommands = liste.length let description = `Sélectionnez une catégorie parmi les options ci-dessous pour obtenir de l'aide sur les commandes correspondantes.\n Il y a ${totalCommands} commandes disponibles\n\n`; for (const [category, commands] of Object.entries(categories)) { description += `**Catégorie ${category}** (${commands.length})\n`; description += commands.length > 0 ? '> ' + commands.map(command => `\`${command.name}\``).join(', ') : '> Aucune commande dans cette catégorie'; description += '\n\n'; } const embeds = { home: new EmbedBuilder() .setColor('#0099ff') .setTitle('📚 Information') .setDescription(description) .setThumbnail(message.guild.iconURL()) .setTimestamp() .setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})}) }; for (const [category, commands] of Object.entries(categories)) { let description; if (commands.length > 0) { description = commands.map(command => `${command.emote ? ` ${command.emote}` : '🔧'} **${prefix}${command.utilisation ? ` ${command.utilisation}` : ''}**\n \`${command.description}\``).join('\n'); } else { description = 'Aucune commande dans cette catégorie.'; } embeds[category] = new EmbedBuilder() .setColor('#0099ff') .setTitle(`Catégorie ${category}`) .setDescription(description) .setTimestamp() .setFooter({text: `${client.user.tag} © 2024`, iconURL: client.user.displayAvatarURL({dynamic: true})}) } const menu = new StringSelectMenuBuilder() .setCustomId('help_menu') .setPlaceholder('Sélectionnez une catégorie') .addOptions([ { label: 'Accueil', value: 'home' }, ...Object.keys(categories).map(category => ({ label: `Catégorie ${category}`, value: category })), ]); const row = new ActionRowBuilder() .addComponents(menu); const sentMessage = await message.reply({ embeds: [embeds.home], components: [row] }); const filter = i => i.customId === 'help_menu' && i.user.id === message.author.id; const collector = sentMessage.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async (interaction) => { await interaction.update({ embeds: [embeds[interaction.values[0]]] }); }); collector.on('end', () => { sentMessage.edit({ components: [] }); }); }, };