const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); module.exports = { name: 'help', description: 'List available bot commands and what they do.', enabled: true, builder: new SlashCommandBuilder() .setName('help') .setDescription('List available bot commands and what they do.') .addStringOption(opt => opt.setName('command').setDescription('Get detailed help for a specific command').setRequired(false)), async execute(interaction) { try { const api = require('../api'); // fetch authoritative commands list for this guild const commands = await api.getCommands(interaction.guildId) || []; const target = interaction.options.getString('command'); if (target) { const found = commands.find(c => c.name.toLowerCase() === target.toLowerCase()); if (!found) { return await interaction.reply({ content: `No command named "/${target}" found.`, flags: 64 }); } const embed = new EmbedBuilder() .setTitle(`/${found.name} — ${found.locked ? 'Locked' : (found.enabled ? 'Enabled' : 'Disabled')}`) .setDescription(found.description || 'No description available.') .setColor(found.enabled ? 0x22c55e : 0xe11d48) .addFields( { name: 'Usage', value: `/${found.name} ${(found.usage || '').trim() || ''}` }, { name: 'Status', value: found.locked ? 'Locked (cannot be toggled)' : (found.enabled ? 'Enabled' : 'Disabled'), inline: true }, { name: 'Has Slash Builder', value: found.hasSlashBuilder ? 'Yes' : 'No', inline: true } ) .setFooter({ text: 'Use /help to view detailed info about a command.' }); return await interaction.reply({ embeds: [embed], flags: 64 }); } // Build a neat embed listing commands grouped by status const embed = new EmbedBuilder() .setTitle('Available Commands') .setDescription('Use `/help ` to get detailed info on a specific command.') .setColor(0x5865f2); // Sort commands: enabled first, then disabled, locked last const sorted = commands.slice().sort((a, b) => { const ka = a.locked ? 2 : (a.enabled ? 0 : 1); const kb = b.locked ? 2 : (b.enabled ? 0 : 1); if (ka !== kb) return ka - kb; return a.name.localeCompare(b.name); }); // Build a concise field list (max 25 fields in Discord embed) const fields = []; for (const cmd of sorted) { const status = cmd.locked ? '🔒 Locked' : (cmd.enabled ? '✅ Enabled' : '⛔ Disabled'); fields.push({ name: `/${cmd.name}`, value: `${cmd.description || 'No description.'}\n${status}`, inline: false }); if (fields.length >= 24) break; } if (fields.length > 0) embed.addFields(fields); else embed.setDescription('No commands available.'); return await interaction.reply({ embeds: [embed], flags: 64 }); } catch (e) { console.error('Error in help command:', e && e.message ? e.message : e); return await interaction.reply({ content: 'Failed to retrieve commands. Try again later.', flags: 64 }); } }, };