© 2026 Hedgehog Software, LLC
import { InteractionHandler, InteractionHandlerTypes } from '@sapphire/framework'; import type { AutocompleteInteraction } from 'discord.js'; export class AutocompleteHandler extends InteractionHandler { public constructor(ctx: InteractionHandler.LoaderContext, options: InteractionHandler.Options) { super(ctx, { ...options, interactionHandlerType: InteractionHandlerTypes.Autocomplete }); } public override async run(interaction: AutocompleteInteraction, result: InteractionHandler.ParseResult<this>) { return interaction.respond(result); } public override async parse(interaction: AutocompleteInteraction) { if (interaction.commandName !== 'panel') return this.none(); const focusedOption = interaction.options.getFocused(true); switch (focusedOption.name) { case 'panel': { const searchResult = this.container.prisma.ticketPanel.findMany({ where: { guildId: interaction.guildId! } }); // Map the search results to the structure required for Autocomplete return this.some( (await searchResult).map((panel) => ({ name: panel.title, value: panel.id, description: panel.description })) ); } default: return this.none(); } } }
Join the Discord to ask follow-up questions and connect with the community
Sapphire is a next-gen object-oriented Discord.js bot framework.
2,286 Members