blob: 1a0ce16b50dddf99755c456b9691a14dca511f34 [file] [log] [blame]
TheCodedProf1c3ad3c2023-01-25 17:58:36 -05001import { ActionRowBuilder, CommandInteraction, StringSelectMenuBuilder, ApplicationCommand, ApplicationCommandOptionType } from "discord.js";
pineafan4f164f32022-02-26 22:07:12 +00002import { SlashCommandBuilder } from "@discordjs/builders";
TheCodedProf1c3ad3c2023-01-25 17:58:36 -05003import client from "../utils/client.js";
4import EmojiEmbed from "../utils/generateEmojiEmbed.js";
5import { LoadingEmbed } from "../utils/defaults.js";
pineafan4f164f32022-02-26 22:07:12 +00006
PineaFan752af462022-12-31 21:59:38 +00007const command = new SlashCommandBuilder()
8 .setName("help")
9 .setDescription("Shows help for commands");
pineafan4f164f32022-02-26 22:07:12 +000010
pineafan63fc5e22022-08-04 22:04:10 +010011const callback = async (interaction: CommandInteraction): Promise<void> => {
TheCodedProf1c3ad3c2023-01-25 17:58:36 -050012 const m = await interaction.reply({ embeds: LoadingEmbed, fetchReply: true });
13 const commands = client.fetchedCommands;
14
15 const commandRow = new ActionRowBuilder<StringSelectMenuBuilder>()
16 .addComponents(
17 commands.map((command) => {
18 return new StringSelectMenuBuilder()
19 .setCustomId(command.name)
20 .setPlaceholder("Select a command")
21 .addOptions({
22 label: command.name,
23 value: command.name
24 })
25 })
26 );
27
28 let closed = false;
29 do {
30 let current: ApplicationCommand | undefined;
31 const subcommandGroupRow = new ActionRowBuilder<StringSelectMenuBuilder>()
32 .addComponents(
33 new StringSelectMenuBuilder()
34 .setCustomId("subcommandGroupRow")
35 );
36 const subcommandRow = new ActionRowBuilder<StringSelectMenuBuilder>()
37 .addComponents(
38 new StringSelectMenuBuilder()
39 .setCustomId("subcommandRow")
40 );
41 const embed = new EmojiEmbed()
42 .setTitle("Help")
43 .setStatus("Success")
44 .setEmoji("📖")
45
46 if(!current) {
47 embed.setDescription(
48 `**${"Help Menu Home"}**\n\n` +
49 `${"Select a command to get started"}`
50 )
51 } else {
52 embed.setDescription(
53 `**${current.name}**\n\n` +
54 `${current.description}`
55 )
56 if(current.options.filter((option) => option.type === ApplicationCommandOptionType.SubcommandGroup).length > 0) {
57 subcommandGroupRow.components[0]!
58 .addOptions(
59 current.options.filter((option) => option.type === ApplicationCommandOptionType.SubcommandGroup).map((option) => {
60 return {
61 label: option.name,
62 value: option.name
63 }
64 })
65 )
66 } else {
67 if(current.options.filter((option) => option.type === ApplicationCommandOptionType.Subcommand).length > 0) {
68 subcommandRow.components[0]!
69 .addOptions(
70 current.options.filter((option) => option.type === ApplicationCommandOptionType.Subcommand).map((option) => {
71 return {
72 label: option.name,
73 value: option.name
74 }
75 })
76 )
77 }
78 }
79 }
80 let cmps = [commandRow];
81 if(subcommandGroupRow.components[0]!.options.length > 0) cmps.push(subcommandGroupRow);
82 if(subcommandRow.components[0]!.options.length > 0) cmps.push(subcommandRow);
83
84 await interaction.editReply({ embeds: [embed], components: cmps });
85
86 } while (!closed);
pineafan63fc5e22022-08-04 22:04:10 +010087};
pineafan4f164f32022-02-26 22:07:12 +000088
PineaFan0d06edc2023-01-17 22:10:31 +000089const check = () => {
pineafan4f164f32022-02-26 22:07:12 +000090 return true;
pineafan63fc5e22022-08-04 22:04:10 +010091};
pineafan4f164f32022-02-26 22:07:12 +000092
93export { command };
94export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +010095export { check };