{"record":{"id":"a57d8456f95ab67b","repo":"discordjs/discord.js","slug":"commandinteractionoptionempty","errorCode":"CommandInteractionOptionEmpty","errorMessage":"CommandInteractionOptionEmpty","messagePattern":"CommandInteractionOptionEmpty","errorType":"error_code","errorClass":"DiscordjsTypeError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/structures/CommandInteractionOptionResolver.js","lineNumber":112,"sourceCode":"\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\n    return this._subcommand;\n  }","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/structures/CommandInteractionOptionResolver.js#L94-L130","documentation":"CommandInteractionOptionEmpty is thrown by _getTypedOption when an option is required, has the correct type, but all of its relevant value properties (e.g. value, user, channel, member) are null/undefined. This happens when Discord delivers an option object that carries no usable value for the requested type.","triggerScenarios":"Calling a typed accessor with required=true for an option whose resolved object has all checked properties null/undefined — e.g. a user option where neither value nor user/member is populated; usually due to desync between the command registration and handler expectations or an unfilled-but-required option sent by Discord.","commonSituations":"Accessing option value properties that don't exist for that option type (expecting `user` on a string option); stale command registration after changing option types; autocomplete flows where values are not yet resolved; race with command registration updates.","solutions":["Verify the properties you expect exist for the option's actual type (a Channel option has `channel`, a User option has `user` and `member`, etc.)","Re-check the command registration matches the builder and redeploy commands","Make the accessor non-required and validate the returned null yourself for optional input","Log `interaction.options.data` to see exactly what Discord populated for the option"],"exampleFix":"// before\nconst user = interaction.options.getUser('user', true); // option is actually a channel-type\n// after\nconst user = interaction.options.getUser('user'); // returns null safely, then validate\nif (!user) return interaction.reply({ content: 'Please provide a user.', ephemeral: true });","handlingStrategy":"validation","validationCode":"const opt = interaction.options.data.find(o => o.name === 'user');\nif (!opt || (opt.user == null && opt.value == null)) {\n  return interaction.reply({ content: 'Please provide a user.', ephemeral: true });\n}","typeGuard":"function hasOptionValue(opt) {\n  return opt != null && ['value','user','member','channel','role','attachment'].some(p => opt[p] != null);\n}","tryCatchPattern":"try {\n  const user = interaction.options.getUser('user', true);\n} catch (err) {\n  if (err.code === 'CommandInteractionOptionEmpty') {\n    return interaction.reply({ content: 'The user option came back empty.', ephemeral: true });\n  }\n  throw err;\n}","preventionTips":["Check the option object shape matches its type before accessing value properties","Redeploy commands when schema changes to avoid stale registrations","Treat required=false and validate nulls explicitly for robustness","Log options.data when debugging empty payloads"],"tags":["discord-js","slash-commands","missing-value"],"backgroundTag":"command-option-empty","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}