Autocomplete handler not working

I made a interaction-handlers folder adjacent to my commands folder and have this code as a .ts file inside:
// @ts-nocheck
import { InteractionHandler, InteractionHandlerTypes, PieceContext } from '@sapphire/framework';
import type { AutocompleteInteraction } from 'discord.js';
export class AuthorizationAutocompleteHandler extends InteractionHandler {
public constructor(ctx: PieceContext, options: InteractionHandler.Options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Autocomplete
});
}
public override async run(interaction: AutocompleteInteraction, result: InteractionHandler.ParseResult<this>) {
console.log('hi')
return interaction.respond(result);
}
public override async parse(interaction: AutocompleteInteraction) {
'foo';
console.log('autocompleting')
if (interaction.commandId !== '1049470193220452402' || interaction.commandId !== '1049470194118054061') return this.none();

const focusedOption = interaction.options.getFocused(true);

switch (focusedOption.name) {
case 'topic': {
const typedTopicName = focusedOption.name as string;
const topicId = focusedOption.value as string;
typedTopicName;
topicId;

const searchResult = new Map();
searchResult.set('12345', 'An Entry');
return this.some(Array.from(searchResult).map((k, v) => ({ name: k, value: v })));
}
default:
return this.none();
}
}
}
// @ts-nocheck
import { InteractionHandler, InteractionHandlerTypes, PieceContext } from '@sapphire/framework';
import type { AutocompleteInteraction } from 'discord.js';
export class AuthorizationAutocompleteHandler extends InteractionHandler {
public constructor(ctx: PieceContext, options: InteractionHandler.Options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Autocomplete
});
}
public override async run(interaction: AutocompleteInteraction, result: InteractionHandler.ParseResult<this>) {
console.log('hi')
return interaction.respond(result);
}
public override async parse(interaction: AutocompleteInteraction) {
'foo';
console.log('autocompleting')
if (interaction.commandId !== '1049470193220452402' || interaction.commandId !== '1049470194118054061') return this.none();

const focusedOption = interaction.options.getFocused(true);

switch (focusedOption.name) {
case 'topic': {
const typedTopicName = focusedOption.name as string;
const topicId = focusedOption.value as string;
typedTopicName;
topicId;

const searchResult = new Map();
searchResult.set('12345', 'An Entry');
return this.some(Array.from(searchResult).map((k, v) => ({ name: k, value: v })));
}
default:
return this.none();
}
}
}
` I'm not seeing any console logs. Any thoughts?
Solution:
Solved it. @Answer Overflow I didn't have .setAutocomplete(true)....
Jump to solution
8 Replies
Spinel
Spinel3y ago
- Did you use a folder of the examples repository or did you use the CLI to generate your bot? - What's your file/folder structure? - What's your "main" property in package.json - Are you using TypeScript? And if so, how are you compiling and running your code? - Are you using the version 2 or version 3 of @sapphire/framework? - In case you are using version 3 of @sapphire/framework, and your problem related to message commands, did you add loadMessageCommandListeners to your SapphireClient options Remember that if you are new to @sapphire/framework it is important that you read the user guide.
Gavan
GavanOP3y ago
Gavan
GavanOP3y ago
v3 TypeScript "scripts": { "build": "tsc", "watch": "tsc -w", "start": "node dist/index.js", "dev": "run-s build start", "watch:start": "tsc-watch --onSuccess "node ./dist/index.js"", "format": "prettier --write "src/*/.ts"" }, "main": "dist/index.js",
Favna
Favna3y ago
You're missing a parse method. Read our guide on interaction handlers: https://www.sapphirejs.dev/docs/Guide/application-commands/interaction-handlers/what-are-they
Sapphire Framework
What are they? | Sapphire
These are interaction handlers! A simple class you can extend to handle almost all the interactions you may receive in
Gavan
GavanOP3y ago
@Favna I'm not sure I follow. Isn't this one about a third of the way down? public override async parse( I do see that I'm kinda doing everything in parse, which I should change, but I still should be getting the console.log('autocompleting')
Solution
Gavan
Gavan3y ago
Solved it. @Answer Overflow I didn't have .setAutocomplete(true).
Favna
Favna3y ago
Feel free to mark your own answer as the solution with @Answer Overflow
Want results from more Discord servers?
Add your server