discordjs/discord.js · error · DiscordjsTypeError
CommandInteractionOptionNotFound
CommandInteractionOptionNotFound
Error message
CommandInteractionOptionNotFound
What it means
CommandInteractionOptionNotFound is thrown by CommandInteractionOptionResolver#get when a required option with the given name cannot be found among the interaction's hoisted options. The library throws it only when `required` is true, because the option name passed does not match any option the user actually supplied in the slash command invocation. It means your code asked for an option that either doesn't exist in the command registration or wasn't provided by the user.
Source
Thrown at packages/discord.js/src/structures/CommandInteractionOptionResolver.js:86
*
* @name CommandInteractionOptionResolver#resolved
* @type {?Readonly<CommandInteractionResolvedData>}
*/
Object.defineProperty(this, 'resolved', { value: resolved ? Object.freeze(resolved) : null });
}
/**
* Gets an option by its name.
*
* @param {string} name The name of the option.
* @param {boolean} [required=false] Whether to throw an error if the option is not found.
* @returns {?CommandInteractionOption} The option, if found.
*/
get(name, required = false) {
const option = this._hoistedOptions.find(opt => opt.name === name);
if (!option) {
if (required) {
throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionNotFound, name);
}
return null;
}
return option;
}
/**
* Gets an option by name and property and checks its type.
*
* @param {string} name The name of the option.
* @param {ApplicationCommandOptionType[]} allowedTypes The allowed types of the option.
* @param {string[]} properties The properties to check for `required`.
* @param {boolean} required Whether to throw an error if the option is not found.
* @returns {?CommandInteractionOption} The option, if found.
* @private
*/View on GitHub (pinned to a81ed8a306)
Solutions
- Ensure the option name string exactly matches the name set in SlashCommandBuilder#add*Option (names are lowercase and underscore-friendly)
- Redeploy/register your application commands after changing option names (guild or global deploy) so Discord sends the new option
- Verify the user actually supplied the option; mark it optional in your code (pass `false` or omit `required`) if it is not required in the builder
- Log `interaction.options.data` to inspect the actual option names received in the interaction
Example fix
// before
const target = interaction.options.get('usr', true); // typo, and option renamed
// after
const target = interaction.options.get('user', true); Defensive patterns
Strategy: validation
Validate before calling
const opt = interaction.options.data.find(o => o.name === 'user');
if (!opt) return interaction.reply({ content: 'Missing option: user', ephemeral: true }); Type guard
function hasOption(interaction, name) {
return interaction.options.data.some(o => o.name === name);
} Try / catch
try {
const target = interaction.options.get('user', true);
} catch (err) {
if (err.code === 'CommandInteractionOptionNotFound') {
return interaction.reply({ content: 'Required option missing.', ephemeral: true });
}
throw err;
} Prevention
- Keep option names in a shared constant module used by both builder and handler
- Redeploy commands on every change to option names (CI step for command registration)
- Use interaction.options.data logging in dev builds to verify payloads
- Only pass required=true for options marked .setRequired(true) in the builder
When it happens
Trigger: Calling resolver.get('name', true) (directly or via helpers like getInteger/getString/option()) with a name that does not match a registered/hoisted option; renaming an option in your command definition without updating the interaction handler; a typo in the option name.
Common situations: Developers rename options in the command builder but forget to redeploy/register the updated command to Discord; typos between builder option names and resolver calls; reading options with `required=true` for optional options; stale local cache of registered commands after changing option names.
Related errors
- CommandInteractionOptionType
- CommandInteractionOptionEmpty
- CommandInteractionOptionNoSubcommand
- CommandInteractionOptionNoSubcommandGroup
- CommandInteractionOptionInvalidChannelType
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/4684eb5c97c948f0.
Report an issue: GitHub.