{"record":{"id":"aa23772a804b8326","repo":"discordjs/discord.js","slug":"commandinteractionoptiontype","errorCode":"CommandInteractionOptionType","errorMessage":"CommandInteractionOptionType","messagePattern":"CommandInteractionOptionType","errorType":"error_code","errorClass":"DiscordjsTypeError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/structures/CommandInteractionOptionResolver.js","lineNumber":110,"sourceCode":"    return option;\n  }\n\n  /**\n   * Gets an option by name and property and checks its type.\n   *\n   * @param {string} name The name of the option.\n   * @param {ApplicationCommandOptionType[]} allowedTypes The allowed types of the option.\n   * @param {string[]} properties The properties to check for `required`.\n   * @param {boolean} required Whether to throw an error if the option is not found.\n   * @returns {?CommandInteractionOption} The option, if found.\n   * @private\n   */\n  _getTypedOption(name, allowedTypes, properties, required) {\n    const option = this.get(name, required);\n    if (!option) {\n      return null;\n    } else if (!allowedTypes.includes(option.type)) {\n      throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionType, name, option.type, allowedTypes.join(', '));\n    } else if (required && properties.every(prop => option[prop] === null || option[prop] === undefined)) {\n      throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionEmpty, name, option.type);\n    }\n\n    return option;\n  }\n\n  /**\n   * Gets the selected subcommand.\n   *\n   * @param {boolean} [required=true] Whether to throw an error if there is no subcommand.\n   * @returns {?string} The name of the selected subcommand, or null if not set and not required.\n   */\n  getSubcommand(required = true) {\n    if (required && !this._subcommand) {\n      throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionNoSubcommand);\n    }\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/structures/CommandInteractionOptionResolver.js#L92-L128","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst count = interaction.options.getInteger('count'); // registered as String\n// after\nconst count = parseInt(interaction.options.getString('count'), 10); // or change builder to addIntegerOption","handlingStrategy":"validation","validationCode":"const opt = interaction.options.data.find(o => o.name === 'count');\nif (opt && opt.type !== ApplicationCommandOptionType.Integer) {\n  return interaction.reply({ content: 'count must be an integer', ephemeral: true });\n}","typeGuard":"function isOptionOfType(opt, type) {\n  return !!opt && opt.type === type;\n}","tryCatchPattern":"try {\n  const n = interaction.options.getInteger('count', true);\n} catch (err) {\n  if (err.code === 'CommandInteractionOptionType') {\n    return interaction.reply({ content: 'Option has the wrong type.', ephemeral: true });\n  }\n  throw err;\n}","preventionTips":["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"],"tags":["discord-js","slash-commands","type-mismatch"],"backgroundTag":"command-option-type-mismatch","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}