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();
}
}
}
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();
}
}
}