(client)
| 27 | } |
| 28 | |
| 29 | export function buildCommandRegistry(client) { |
| 30 | const categories = new Map(); |
| 31 | |
| 32 | for (const command of client.commands.values()) { |
| 33 | if (!command?.data?.name) { |
| 34 | continue; |
| 35 | } |
| 36 | |
| 37 | const category = command.category || 'Core'; |
| 38 | const categoryKey = normalizeCategoryKey(category); |
| 39 | |
| 40 | if (!categories.has(categoryKey)) { |
| 41 | categories.set(categoryKey, { |
| 42 | key: categoryKey, |
| 43 | folder: category, |
| 44 | displayName: formatCategoryName(category), |
| 45 | icon: getCategoryIcon(category), |
| 46 | commands: [], |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | // Add the main command |
| 51 | categories.get(categoryKey).commands.push({ |
| 52 | name: command.data.name, |
| 53 | description: command.data.description || 'No description', |
| 54 | protected: PROTECTED_COMMANDS.has(command.data.name.toLowerCase()), |
| 55 | isSubcommand: false, |
| 56 | }); |
| 57 | |
| 58 | // Add subcommands if they exist |
| 59 | const commandJson = command.data.toJSON?.() || {}; |
| 60 | |
| 61 | for (const option of commandJson.options || []) { |
| 62 | if (option.type === 1) { |
| 63 | const subcommandName = `${command.data.name} ${option.name}`; |
| 64 | categories.get(categoryKey).commands.push({ |
| 65 | name: subcommandName, |
| 66 | description: option.description || 'No description', |
| 67 | protected: false, |
| 68 | isSubcommand: true, |
| 69 | parentCommand: command.data.name, |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | if (option.type === 2) { |
| 74 | for (const sub of option.options || []) { |
| 75 | if (sub.type === 1) { |
| 76 | const subcommandName = `${command.data.name} ${option.name} ${sub.name}`; |
| 77 | categories.get(categoryKey).commands.push({ |
| 78 | name: subcommandName, |
| 79 | description: sub.description || 'No description', |
| 80 | protected: false, |
| 81 | isSubcommand: true, |
| 82 | parentCommand: command.data.name, |
| 83 | }); |
| 84 | } |
| 85 | } |
| 86 | } |
no test coverage detected