(client)
| 51 | } |
| 52 | |
| 53 | export async function loadCommands(client) { |
| 54 | client.commands = new Collection(); |
| 55 | const commandsPath = path.join(__dirname, '../commands'); |
| 56 | const commandFiles = await getAllFiles(commandsPath); |
| 57 | |
| 58 | logger.info(`Found ${commandFiles.length} command files to load`); |
| 59 | |
| 60 | const uniqueCommandNames = new Set(); |
| 61 | |
| 62 | for (const filePath of commandFiles) { |
| 63 | try { |
| 64 | const normalizedPath = filePath.replace(/\\/g, '/'); |
| 65 | |
| 66 | const commandName = path.basename(filePath, '.js'); |
| 67 | const commandDir = path.dirname(filePath); |
| 68 | const category = path.basename(commandDir); |
| 69 | |
| 70 | const commandModule = await import(`file://${filePath}`); |
| 71 | const command = commandModule.default || commandModule; |
| 72 | |
| 73 | if (!command.data || !command.execute) { |
| 74 | logger.warn(`Command at ${filePath} is missing required "data" or "execute" property.`); |
| 75 | continue; |
| 76 | } |
| 77 | |
| 78 | command.category = category; |
| 79 | command.filePath = normalizedPath; |
| 80 | |
| 81 | const primaryCommandName = command.data.name; |
| 82 | |
| 83 | if (!uniqueCommandNames.has(primaryCommandName)) { |
| 84 | uniqueCommandNames.add(primaryCommandName); |
| 85 | |
| 86 | client.commands.set(primaryCommandName, command); |
| 87 | } |
| 88 | |
| 89 | const subcommands = getSubcommandInfo(command.data.toJSON()); |
| 90 | |
| 91 | logger.info(`Loaded command: ${primaryCommandName} from ${normalizedPath} (category: ${category})`); |
| 92 | |
| 93 | if (subcommands.length > 0) { |
| 94 | logger.info(` - Subcommands: ${subcommands.join(', ')}`); |
| 95 | } |
| 96 | |
| 97 | } catch (error) { |
| 98 | logger.error(`Error loading command from ${filePath}:`, error); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | const commandsWithSubcommands = Array.from(client.commands.values()).filter(cmd => { |
| 103 | const subcommands = getSubcommandInfo(cmd.data.toJSON()); |
| 104 | return subcommands.length > 0; |
| 105 | }); |
| 106 | |
| 107 | const totalSubcommands = commandsWithSubcommands.reduce((total, cmd) => { |
| 108 | return total + getSubcommandInfo(cmd.data.toJSON()).length; |
| 109 | }, 0); |
| 110 |
no test coverage detected