blob: 719855fb179ffb1a2e04ca7b0c03d0b75eb3e3c8 [file] [log] [blame]
PineaFan64486c42022-12-28 09:21:04 +00001import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
2import type { SlashCommandBuilder } from "discord.js";
3import config from "../../config/main.json" assert { type: "json" };
4import getSubcommandsInFolder from "./getFilesInFolder.js";
5
6
7export 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
22export 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}