{"record":{"id":"5f394eff93aff3aa","repo":"discordjs/discord.js","slug":"commandinteractionoptionnosubcommand","errorCode":"CommandInteractionOptionNoSubcommand","errorMessage":"CommandInteractionOptionNoSubcommand","messagePattern":"CommandInteractionOptionNoSubcommand","errorType":"error_code","errorClass":"DiscordjsTypeError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/structures/CommandInteractionOptionResolver.js","lineNumber":126,"sourceCode":"      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  }\n\n  /**\n   * Gets the selected subcommand group.\n   *\n   * @param {boolean} [required=false] Whether to throw an error if there is no subcommand group.\n   * @returns {?string} The name of the selected subcommand group, or null if not set and not required.\n   */\n  getSubcommandGroup(required = false) {\n    if (required && !this._group) {\n      throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionNoSubcommandGroup);\n    }\n\n    return this._group;\n  }","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/structures/CommandInteractionOptionResolver.js#L108-L144","documentation":"CommandInteractionOptionNoSubcommand is thrown by getSubcommand when `required` (default true) is passed and no subcommand was selected in the interaction. It indicates the code expects the interaction to have targeted a subcommand, but the invoked command either has no subcommands at that level or the user ran the top-level command.","triggerScenarios":"Calling interaction.options.getSubcommand() (default required=true) on an interaction that resolved without a subcommand — e.g. the command was invoked at its top level, or the command has no subcommand options; calling it inside a subcommand-group handler at the wrong nesting level.","commonSituations":"A top-level command handler that serves both subcommand and non-subcommand invocations; forgetting getSubcommandGroup() consumed the group level so getSubcommand is called expecting the group; shared handler code reused across commands where some lack subcommands.","solutions":["Pass getSubcommand(false) and handle null when subcommands are optional","Check the focused group first: when a subcommand group is selected, read it with getSubcommandGroup() before getSubcommand()","Ensure the handler is only attached to commands that actually define subcommands","Register/handle a default (non-subcommand) execution path or make the top-level command not executable"],"exampleFix":"// before\nconst sub = interaction.options.getSubcommand(); // throws when user ran top-level command\n// after\nconst sub = interaction.options.getSubcommand(false);\nif (!sub) return interaction.reply('Specify a subcommand.');","handlingStrategy":"validation","validationCode":"const sub = interaction.options.getSubcommand(false);\nif (!sub) return interaction.reply({ content: 'Please choose a subcommand.', ephemeral: true });","typeGuard":"function hasSubcommand(interaction) {\n  return interaction.options.data.some(o => o.type === ApplicationCommandOptionType.Subcommand);\n}","tryCatchPattern":"try {\n  const sub = interaction.options.getSubcommand();\n} catch (err) {\n  if (err.code === 'CommandInteractionOptionNoSubcommand') {\n    return interaction.reply({ content: 'This command requires a subcommand.', ephemeral: true });\n  }\n  throw err;\n}","preventionTips":["Handle group vs subcommand lookup order explicitly in dispatchers","Only call getSubcommand() in handlers registered to subcommand-capable commands","Use getSubcommand(false) whenever subcommands are optional","Build a router keyed by subcommand names from the builder schema"],"tags":["discord-js","slash-commands","subcommand"],"backgroundTag":"missing-subcommand","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}