discordjs/discord.js · error · DiscordjsTypeError
AutocompleteInteractionOptionNoFocusedOption
AutocompleteInteractionOptionNoFocusedOption
Error message
AutocompleteInteractionOptionNoFocusedOption
What it means
AutocompleteInteractionOptionNoFocusedOption is thrown by getFocused when the interaction's hoisted options contain none marked as focused. Only autocomplete interactions carry a focused option; calling getFocused() on a non-autocomplete interaction or an autocomplete payload without focused data triggers this error.
Source
Thrown at packages/discord.js/src/structures/CommandInteractionOptionResolver.js:331
/**
* The full autocomplete option object.
*
* @typedef {Object} AutocompleteFocusedOption
* @property {string} name The name of the option
* @property {ApplicationCommandOptionType} type The type of the application command option
* @property {string} value The value of the option
* @property {boolean} focused Whether this option is currently in focus for autocomplete
*/
/**
* Gets the focused option.
*
* @returns {AutocompleteFocusedOption}
* The whole object of the option that is focused
*/
getFocused() {
const focusedOption = this._hoistedOptions.find(option => option.focused);
if (!focusedOption) throw new DiscordjsTypeError(ErrorCodes.AutocompleteInteractionOptionNoFocusedOption);
return focusedOption;
}
}
exports.CommandInteractionOptionResolver = CommandInteractionOptionResolver;
View on GitHub (pinned to a81ed8a306)
Solutions
- Only call getFocused() inside an autocomplete callback (setAutocomplete / interaction.isAutocomplete())
- Pass the boolean `getOptionFocused`/use interaction.isAutocomplete() to branch before calling getFocused()
- Ensure respond([...]) is called on the interaction in the autocomplete path so Discord doesn't show 'thinking' failures
- Guard the handler: check interaction.isChatInputCommand() vs isAutocomplete() before using option accessors
Example fix
// before
async run(interaction) {
const focused = interaction.options.getFocused(); // crashes on normal executions
}
// after
async autocomplete(interaction) {
if (!interaction.isAutocomplete()) return;
const focused = interaction.options.getFocused();
await interaction.respond(choices.filter(c => c.startsWith(focused.value)));
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!interaction.isAutocomplete()) return; const focused = interaction.options.data.find(o => o.focused); if (!focused) return interaction.respond([]);
Type guard
function isAutocompleteInteraction(interaction) {
return interaction.isAutocomplete?.() === true;
} Try / catch
try {
const focused = interaction.options.getFocused();
} catch (err) {
if (err.code === 'AutocompleteInteractionOptionNoFocusedOption') {
return interaction.respond([]);
}
throw err;
} Prevention
- Register autocomplete logic via setAutocomplete, never in execute()
- Always call interaction.respond() in autocomplete handlers
- Branch with interaction.isAutocomplete() when sharing handlers
- Test autocomplete on a real guild before global rollout
When it happens
Trigger: Calling interaction.options.getFocused() inside a regular slash command handler instead of the autocomplete handler; wiring an autocomplete callback to the wrong event/handler so it runs for command executions; Discord sending an autocomplete interaction without the focused flag (rare payload anomaly).
Common situations: Copy-pasted autocomplete handler attached to the execute path of a command; a single handler used for both execute and autocomplete without checking interaction.isAutocomplete(); respond() never being called so the interaction errors out client-side.
Related errors
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/1eb825745e195fb4.
Report an issue: GitHub.