fix: some type issues in handleAutocomplete

This commit is contained in:
Jozef Steinhübl 2023-08-24 16:13:15 +02:00
parent 0c5f2d21c1
commit 7e6f7b12ae

View file

@ -1,9 +1,9 @@
import { Events, Interaction, ChatInputCommandInteraction, AutocompleteInteraction } from "discord.js"; import { Events, Interaction, ChatInputCommandInteraction, AutocompleteInteraction, APIApplicationCommandSubcommandOption, APIApplicationCommandSubcommandGroupOption } from "discord.js";
import { COMMANDS } from "../loaders/commands.ts"; import { COMMANDS } from "../loaders/commands.ts";
import { defineListener } from "../loaders/listeners.ts"; import { defineListener } from "../loaders/listeners.ts";
import { InteractionCommandContext } from "../structs/context/CommandContext.ts"; import { InteractionCommandContext } from "../structs/context/CommandContext.ts";
import { AutocompleteContext } from "../structs/context/AutocompleteContext.ts"; import { AutocompleteContext } from "../structs/context/AutocompleteContext.ts";
import { StringOption } from "../structs/Command.ts"; import { Option, StringOption } from "../structs/Command.ts";
defineListener({ defineListener({
event: Events.InteractionCreate, event: Events.InteractionCreate,
@ -42,10 +42,11 @@ async function handleAutocomplete(interaction: AutocompleteInteraction) {
let options = command.options; let options = command.options;
if (interaction.options.getSubcommandGroup(false)) if (interaction.options.getSubcommandGroup(false))
options = options.find(o => o.name === interaction.options.getSubcommandGroup())?.options; options = (options.find(o => o.name === interaction.options.getSubcommandGroup()) as APIApplicationCommandSubcommandGroupOption)?.options as Option[];
if (interaction.options.getSubcommand(false)) if (interaction.options.getSubcommand(false))
options = options.find(o => o.name === interaction.options.getSubcommand())?.options; options = (options.find(o => o.name === interaction.options.getSubcommand()) as APIApplicationCommandSubcommandOption)?.options as Option[];
const focused = interaction.options.getFocused(true); const focused = interaction.options.getFocused(true);
const option = options.find(o => o.name === focused.name) as StringOption; const option = options.find(o => o.name === focused.name) as StringOption;