Skip to content

Commit

Permalink
fix: /dict delete <word> autocomplete issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yuimarudev committed Dec 1, 2024
1 parent 612484f commit 62e1bd7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/commands/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
APIApplicationCommandAutocompleteInteraction,
APIApplicationCommandInteractionDataStringOption,
APIApplicationCommandInteractionDataSubcommandOption,
APIApplicationCommandStringOption,
APIChatInputApplicationCommandInteraction,
APIInteractionGuildMember,
ApplicationCommandOptionType,
RESTPostAPIChatInputApplicationCommandsJSONBody,
} from "@discordjs/core";
import { transmute } from "../commons/functions.js";
Expand Down Expand Up @@ -188,15 +190,21 @@ export default class Dict implements ICommand {
if (command.name === "delete") {
let cache = wordsCache.get(i.guild_id);

if (!cache) {
if (!cache || !cache.length) {
cache = await prisma.dictionary.findMany({
where: { guildId: i.guild_id },
});
wordsCache.set(i.guild_id, cache);
}

const focusedOption = command.options?.find(
(x) => x.type === ApplicationCommandOptionType.String && x.focused,
) as APIApplicationCommandInteractionDataStringOption | undefined;

await api.interactions.createAutocompleteResponse(i.id, i.token, {
choices: cache.map((x) => ({ name: x.word, value: x.word })),
choices: cache
.filter((x) => x.word.startsWith(focusedOption?.value ?? ""))
.map((x) => ({ name: x.word, value: x.word })),
});
}
}
Expand Down

0 comments on commit 62e1bd7

Please sign in to comment.