{"record":{"id":"1eb825745e195fb4","repo":"discordjs/discord.js","slug":"autocompleteinteractionoptionnofocusedoption","errorCode":"AutocompleteInteractionOptionNoFocusedOption","errorMessage":"AutocompleteInteractionOptionNoFocusedOption","messagePattern":"AutocompleteInteractionOptionNoFocusedOption","errorType":"error_code","errorClass":"DiscordjsTypeError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/structures/CommandInteractionOptionResolver.js","lineNumber":331,"sourceCode":"  /**\n   * The full autocomplete option object.\n   *\n   * @typedef {Object} AutocompleteFocusedOption\n   * @property {string} name The name of the option\n   * @property {ApplicationCommandOptionType} type The type of the application command option\n   * @property {string} value The value of the option\n   * @property {boolean} focused Whether this option is currently in focus for autocomplete\n   */\n\n  /**\n   * Gets the focused option.\n   *\n   * @returns {AutocompleteFocusedOption}\n   * The whole object of the option that is focused\n   */\n  getFocused() {\n    const focusedOption = this._hoistedOptions.find(option => option.focused);\n    if (!focusedOption) throw new DiscordjsTypeError(ErrorCodes.AutocompleteInteractionOptionNoFocusedOption);\n    return focusedOption;\n  }\n}\n\nexports.CommandInteractionOptionResolver = CommandInteractionOptionResolver;\n","sourceCodeStart":313,"sourceCodeEnd":337,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/structures/CommandInteractionOptionResolver.js#L313-L337","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nasync run(interaction) {\n  const focused = interaction.options.getFocused(); // crashes on normal executions\n}\n// after\nasync autocomplete(interaction) {\n  if (!interaction.isAutocomplete()) return;\n  const focused = interaction.options.getFocused();\n  await interaction.respond(choices.filter(c => c.startsWith(focused.value)));\n}","handlingStrategy":"type-guard","validationCode":"if (!interaction.isAutocomplete()) return;\nconst focused = interaction.options.data.find(o => o.focused);\nif (!focused) return interaction.respond([]);","typeGuard":"function isAutocompleteInteraction(interaction) {\n  return interaction.isAutocomplete?.() === true;\n}","tryCatchPattern":"try {\n  const focused = interaction.options.getFocused();\n} catch (err) {\n  if (err.code === 'AutocompleteInteractionOptionNoFocusedOption') {\n    return interaction.respond([]);\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["discord-js","autocomplete","focused-option"],"backgroundTag":"no-focused-option","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}