mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 23:27:55 -05:00
Dynamic command building for the q command
This commit is contained in:
@@ -91,13 +91,45 @@ const COMMAND_NAME = "q";
|
||||
|
||||
export const questionCommand: BotCommand = {
|
||||
name: COMMAND_NAME,
|
||||
builder: new SlashCommandBuilder()
|
||||
.setName(COMMAND_NAME)
|
||||
.setDescription("wohoo"),
|
||||
builder: addSubcommands(
|
||||
new SlashCommandBuilder()
|
||||
.setName(COMMAND_NAME)
|
||||
.setDescription("Find a link")
|
||||
),
|
||||
execute: async ({ interaction }) => {
|
||||
return interaction.reply("Pong!");
|
||||
},
|
||||
};
|
||||
|
||||
function addSubcommands(builder: SlashCommandBuilder) {
|
||||
for (const [key, value] of Object.entries(groupedLinks)) {
|
||||
builder.addSubcommand((subcommand) => {
|
||||
const result = subcommand
|
||||
.setName(key)
|
||||
.setDescription(`TODO: explanation for ${key} command`);
|
||||
|
||||
if (typeof value !== "string") {
|
||||
result.addStringOption((option) =>
|
||||
option
|
||||
.setName("name")
|
||||
.setDescription("TODO: subname desc")
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
...Object.keys(value).map((key) => ({
|
||||
name: key.toUpperCase(),
|
||||
value: key,
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
// const questionCommand: BotCommand = {
|
||||
// name: "add",
|
||||
// description: "Gives you the specified role",
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import type { SlashCommandBuilder } from "@discordjs/builders";
|
||||
import type {
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
} from "@discordjs/builders";
|
||||
import type { CommandInteraction } from "discord.js";
|
||||
|
||||
export interface BotCommand {
|
||||
@@ -6,7 +9,7 @@ export interface BotCommand {
|
||||
// description: string;
|
||||
// /** ID's of guilds where this command will be set */
|
||||
// guilds: string[];
|
||||
builder: SlashCommandBuilder;
|
||||
builder: SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder;
|
||||
execute: (commandParameters: {
|
||||
interaction: CommandInteraction;
|
||||
}) => Promise<void>;
|
||||
|
||||
Reference in New Issue
Block a user