javadiscorddiscord-jda

JDA Discord Bot: INTEGER Option Range


I'm working on a Discord bot using JDA (Java Discord API), and I'm having trouble setting up a slash command that includes an INTEGER option with a specific range. Despite going through the official JDA documentation and searching online, I couldn't find a solution that addresses my problem.

Please note that I do not just want to implement a if clause. I want to specifically cause the error seen below.

Image showing a Command where a invalid Number was entered.

Currently I am implementing a slash command like this:

jda.updateCommands().addCommands(
  Commands.slash("casino", "casino commands.")
    .addSubcommands(
      new SubcommandData("slots", "Play slots in the Casino.")
        .addOption(OptionType.INTEGER, "amount", "the amount of money you want to bet.")
    )
).queue();

Solution

  • You can use addOptions to pass in an instance of OptionData with more configuration.

    addOptions(new OptionData(INTEGER, "amount", "...")
      .setRequiredRange(1, 10))