const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder } = require("discord.js"); const { knex } = require("../../db.js"); const configData = {} const data = new SlashCommandBuilder() .setName("userconfig") .setDescription("Manage your user settings") .setContexts([ InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel ]) .setIntegrationTypes([ ApplicationIntegrationType.UserInstall ]); for (const option in configData) { const config = configData[option]; data.addSubcommand((builder) => { builder .setName(option) .setDescription(config.description) switch (config.type) { case "bool": builder.addBooleanOption(builder => builder.setName("value") ); case "channel": builder.addChannelOption(builder => builder.setName("channel") ); default: } }) } module.exports = { data, async execute(interaction) { interaction.reply("Not implemented yet, sorry!"); }, async autocomplete(interaction) { const focusedOption = interaction.options.getFocused(true); const command = interaction.options.getSubcommand(true); console.log(command, focusedOption); const id = ""; const choices = []; for (const option in configData) { if (focusedOption.name == "name" && option.startsWith(focusedOption.value)) choices.push(option); else if (focusedOption.name == "value" && (option == interaction.options.getString("name") ?? "")) choices.push(...buildChoices(option, interaction)); } await interaction.respond(choices.map(choice => ({ name: choice, value: choice }))) }, };