PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame^] | 1 | import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; |
| 2 | import type { SlashCommandBuilder } from "discord.js"; |
| 3 | import config from "../../config/main.json" assert { type: "json" }; |
| 4 | import getSubcommandsInFolder from "./getFilesInFolder.js"; |
| 5 | |
| 6 | |
| 7 | export async function group(name: string, description: string, path: string) { |
| 8 | const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path) |
| 9 | return (subcommandGroup: SlashCommandSubcommandGroupBuilder) => { |
| 10 | subcommandGroup |
| 11 | .setName(name) |
| 12 | .setDescription(description) |
| 13 | |
| 14 | for (const subcommand of fetched.subcommands) { |
| 15 | subcommandGroup.addSubcommand(subcommand); |
| 16 | }; |
| 17 | |
| 18 | return subcommandGroup; |
| 19 | }; |
| 20 | } |
| 21 | |
| 22 | export async function command(name: string, description: string, path: string) { |
| 23 | const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path); |
| 24 | console.log(`│ ├─ Loaded ${fetched.subcommands.length} subcommands and ${fetched.subcommandGroups.length} subcommand groups for ${name}`) |
| 25 | return (command: SlashCommandBuilder) => { |
| 26 | command.setName(name) |
| 27 | command.setDescription(description) |
| 28 | |
| 29 | for (const subcommand of fetched.subcommands) { |
| 30 | command.addSubcommand(subcommand); |
| 31 | } |
| 32 | for (const group of fetched.subcommandGroups) { |
| 33 | command.addSubcommandGroup(group); |
| 34 | }; |
| 35 | return command; |
| 36 | }; |
| 37 | } |