discordjs/discord.js · error · DiscordjsTypeError
CommandInteractionOptionType
CommandInteractionOptionType
Error message
CommandInteractionOptionType
What it means
CommandInteractionOptionType is thrown by _getTypedOption when the resolved option's type is not among the allowed types for the getter used (e.g. calling getInteger on an option that is actually a String). Each typed getter (option, getString, getInteger, getUser, getChannel, etc.) restricts allowedTypes and throws when the actual ApplicationCommandOptionType differs.
Source
Thrown at packages/discord.js/src/structures/CommandInteractionOptionResolver.js:110
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
*/
_getTypedOption(name, allowedTypes, properties, required) {
const option = this.get(name, required);
if (!option) {
return null;
} else if (!allowedTypes.includes(option.type)) {
throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionType, name, option.type, allowedTypes.join(', '));
} else if (required && properties.every(prop => option[prop] === null || option[prop] === undefined)) {
throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionEmpty, name, option.type);
}
return option;
}
/**
* Gets the selected subcommand.
*
* @param {boolean} [required=true] Whether to throw an error if there is no subcommand.
* @returns {?string} The name of the selected subcommand, or null if not set and not required.
*/
getSubcommand(required = true) {
if (required && !this._subcommand) {
throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionNoSubcommand);
}
View on GitHub (pinned to a81ed8a306)
Solutions
- Check the option type in your SlashCommandBuilder definition and use the matching getter (getString for String, getInteger for Integer, getUser for User, etc.)
- Redeploy/re-register the application command after changing an option's type so Discord sends the new type
- If using `option()` with an allowedTypes array, include the actual ApplicationCommandOptionType of the option
- Log `interaction.options.data` to see the actual `type` value Discord sent
Example fix
// before
const count = interaction.options.getInteger('count'); // registered as String
// after
const count = parseInt(interaction.options.getString('count'), 10); // or change builder to addIntegerOption Defensive patterns
Strategy: validation
Validate before calling
const opt = interaction.options.data.find(o => o.name === 'count');
if (opt && opt.type !== ApplicationCommandOptionType.Integer) {
return interaction.reply({ content: 'count must be an integer', ephemeral: true });
} Type guard
function isOptionOfType(opt, type) {
return !!opt && opt.type === type;
} Try / catch
try {
const n = interaction.options.getInteger('count', true);
} catch (err) {
if (err.code === 'CommandInteractionOptionType') {
return interaction.reply({ content: 'Option has the wrong type.', ephemeral: true });
}
throw err;
} Prevention
- Match getter to builder option kind (addIntegerOption -> getInteger)
- Redeploy commands after changing an option's type
- Prefer the dedicated typed getters over the generic option() helper
- Verify with data/*.json command registration files that types match handlers
When it happens
Trigger: Calling a typed accessor like interaction.options.getInteger('x') or interaction.options.option('x', true, [ApplicationCommandOptionType.Integer]) where the registered option 'x' has a different type (e.g. String or User); changing an option's type in the builder without updating handler code or re-registering the command.
Common situations: Migrating an option from string to integer (or user to string) but the old command registration is still cached on Discord's side; generic `option()` helper with an explicit allowedTypes array that mismatches the builder; copy-pasting handler code between commands with same-named but differently-typed options.
Related errors
- CommandInteractionOptionNotFound
- CommandInteractionOptionEmpty
- CommandInteractionOptionNoSubcommand
- CommandInteractionOptionNoSubcommandGroup
- CommandInteractionOptionInvalidChannelType
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/aa23772a804b8326.
Report an issue: GitHub.