Class OptionHelper

java.lang.Object
pw.chew.jdachewtils.command.OptionHelper

@Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public final class OptionHelper extends Object
Deprecated.
Use SlashCommandEvent methods instead.
Utility class containing useful methods for getting values of Slash command arguments.

Example


 public class MyCommand extends SlashCommand {
     public MyCommand() {
         this.name = "example";
         this.help = "Example command";

         this.options = Arrays.asList(
             new OptionData(OptionType.STRING, "string", "A String option").setRequired(true),
             new OptionData(OptionType.USER, "user", "A optional User")
         );
     }

    @Override
     protected void execute(SlashCommandEvent event) {
         // get "string" option as String. Defaults to null if not found
         String arg1 = OptionHelper.optString(event, "string");
         // Get the provided user, or use the executor if they did not provide one
         User optionalUser = OptionHelper.optUser(event, "user", event.getUser());
     }
 }
 
  • Method Details

    • optString

      @Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static String optString(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Gets the provided Option Key as a String value, or returns null if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or null if the option is not present
    • optString

      @Nullable @Contract("_, _, !null -> !null") @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static String optString(@NotNull SlashCommandEvent event, @NotNull String key, @Nullable String defaultValue)
      Gets the provided Option Key as a String value, or returns the default one if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - Nullable default value used in the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optBoolean

      @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static boolean optBoolean(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Gets the provided Option Key as a boolean value, or returns false if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or false if the option is not present
    • optBoolean

      @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static boolean optBoolean(@NotNull SlashCommandEvent event, @NotNull String key, boolean defaultValue)
      Gets the provided Option Key as a boolean value, or returns the default one if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - The fallback option in case of the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optLong

      @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static long optLong(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Gets the provided Option Key as a long value, or returns 0 if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or 0 if the option is not present
    • optLong

      @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static long optLong(@NotNull SlashCommandEvent event, @NotNull String key, long defaultValue)
      Deprecated.
      Gets the provided Option Key as a long value, or returns the default one if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - The fallback option in case of the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optDouble

      @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static double optDouble(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Gets the provided Option Key as a double value, or returns 0.0 if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or 0.0 if the option is not present
    • optDouble

      @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static double optDouble(@NotNull SlashCommandEvent event, @NotNull String key, double defaultValue)
      Gets the provided Option Key as a double value, or returns the default one if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - The fallback option in case of the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optGuildChannel

      @Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.channel.middleman.GuildChannel optGuildChannel(@NotNull SlashCommandEvent event, @NotNull String key)
      Gets the provided Option Key as a GuildChannel value, or returns null if the option cannot be found.
      This will always return null when the SlashCommandEvent was not executed in a Guild.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or null if the option is not present
    • optGuildChannel

      @Nullable @Contract("_, _, !null -> !null") @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.channel.middleman.GuildChannel optGuildChannel(@NotNull SlashCommandEvent event, @NotNull String key, @Nullable net.dv8tion.jda.api.entities.channel.middleman.GuildChannel defaultValue)
      Gets the provided Option Key as a GuildChannel value, or returns the default one if the option cannot be found.
      This will always return the default value when the SlashCommandEvent was not executed in a Guild.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - Nullable default value used in the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optMember

      @Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.Member optMember(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Gets the provided Option Key as a Member value, or returns null if the option cannot be found.
      This will always return null when the SlashCommandEvent was not executed in a Guild.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or null if the option is not present
    • optMember

      @Nullable @Contract("_, _, !null -> !null") @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.Member optMember(@NotNull SlashCommandEvent event, @NotNull String key, @Nullable net.dv8tion.jda.api.entities.Member defaultValue)
      Gets the provided Option Key as a Member value, or returns the default one if the option cannot be found.
      This will always return the default value when the SlashCommandEvent was not executed in a Guild.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - Nullable default value used in the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optMentionable

      @Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.IMentionable optMentionable(@NotNull SlashCommandEvent event, @NotNull String key)
      Gets the provided Option Key as a IMentionable value, or returns null if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or null if the option is not present
    • optMentionable

      @Nullable @Contract("_, _, !null -> !null") @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.IMentionable optMentionable(@NotNull SlashCommandEvent event, @NotNull String key, @Nullable net.dv8tion.jda.api.entities.IMentionable defaultValue)
      Gets the provided Option Key as a IMentionable value, or returns the default one if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - Nullable default value used in the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optRole

      @Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.Role optRole(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Gets the provided Option Key as a Role value, or returns null if the option cannot be found.
      This will always return null when the SlashCommandEvent was not executed in a Guild.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or null if the option is not present
    • optRole

      @Nullable @Contract("_, _, !null -> !null") @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.Role optRole(@NotNull SlashCommandEvent event, @NotNull String key, @Nullable net.dv8tion.jda.api.entities.Role defaultValue)
      Deprecated.
      Gets the provided Option Key as a Role value, or returns the default one if the option cannot be found.
      This will always return the default value when the SlashCommandEvent was not executed in a Guild.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - Nullable default value used in the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optUser

      @Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.User optUser(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Gets the provided Option Key as a User value, or returns null if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or null if the option is not present
    • optUser

      @Nullable @Contract("_, _, !null -> !null") @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.User optUser(@NotNull SlashCommandEvent event, @NotNull String key, @Nullable net.dv8tion.jda.api.entities.User defaultValue)
      Deprecated.
      Gets the provided Option Key as a User value, or returns the default one if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - Nullable default value used in the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • optMessageChannel

      @Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.channel.middleman.MessageChannel optMessageChannel(@NotNull SlashCommandEvent event, @NotNull String key)
      Gets the provided Option Key as a MessageChannel value, or returns null if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      Returns:
      The provided option, or null if the option is not present
    • optMessageChannel

      @Nullable @Contract("_, _, !null -> !null") @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static net.dv8tion.jda.api.entities.channel.middleman.MessageChannel optMessageChannel(@NotNull SlashCommandEvent event, @NotNull String key, @Nullable net.dv8tion.jda.api.entities.channel.middleman.MessageChannel defaultValue)
      Gets the provided Option Key as a MessageChannel value, or returns the default one if the option cannot be found.
      Parameters:
      event - The slash command event to get options from
      key - The option we want
      defaultValue - Nullable default value used in the absence of the option value
      Returns:
      The provided option, or the default value if the option is not present
    • hasOption

      @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static boolean hasOption(@NotNull SlashCommandEvent event, @NotNull String key)
      Deprecated.
      Will return if the provided key resolves into a provided Option for the SlashCommand.
      Parameters:
      event - the slash command event to get options from
      key - the option we want
      Returns:
      true if the option exists, false otherwise