Package pw.chew.jdachewtils.command
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.
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 Summary
Modifier and TypeMethodDescriptionstatic booleanhasOption(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.hasOption(String)instead.static booleanoptBoolean(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optBoolean(String)instead.static booleanoptBoolean(SlashCommandEvent event, String key, boolean defaultValue) Deprecated.UseSlashCommandEvent.optBoolean(String, boolean)instead.static doubleoptDouble(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optDouble(String)instead.static doubleoptDouble(SlashCommandEvent event, String key, double defaultValue) Deprecated.UseSlashCommandEvent.optDouble(String, double)instead.static net.dv8tion.jda.api.entities.channel.middleman.GuildChanneloptGuildChannel(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optGuildChannel(String)instead.static net.dv8tion.jda.api.entities.channel.middleman.GuildChanneloptGuildChannel(SlashCommandEvent event, String key, net.dv8tion.jda.api.entities.channel.middleman.GuildChannel defaultValue) Deprecated.static longoptLong(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optLong(String)instead.static longoptLong(SlashCommandEvent event, String key, long defaultValue) Deprecated.UseSlashCommandEvent.optLong(String, long)instead.static net.dv8tion.jda.api.entities.MemberoptMember(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optMember(String)instead.static net.dv8tion.jda.api.entities.MemberoptMember(SlashCommandEvent event, String key, net.dv8tion.jda.api.entities.Member defaultValue) Deprecated.UseSlashCommandEvent.optMember(String, Member)instead.static net.dv8tion.jda.api.entities.IMentionableoptMentionable(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optMentionable(String)instead.static net.dv8tion.jda.api.entities.IMentionableoptMentionable(SlashCommandEvent event, String key, net.dv8tion.jda.api.entities.IMentionable defaultValue) Deprecated.static net.dv8tion.jda.api.entities.channel.middleman.MessageChanneloptMessageChannel(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optMessageChannel(String)instead.static net.dv8tion.jda.api.entities.channel.middleman.MessageChanneloptMessageChannel(SlashCommandEvent event, String key, net.dv8tion.jda.api.entities.channel.middleman.MessageChannel defaultValue) Deprecated.static net.dv8tion.jda.api.entities.RoleoptRole(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optRole(String)instead.static net.dv8tion.jda.api.entities.RoleoptRole(SlashCommandEvent event, String key, net.dv8tion.jda.api.entities.Role defaultValue) Deprecated.UseSlashCommandEvent.optRole(String, Role)instead.static StringoptString(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optString(String)instead.static StringoptString(SlashCommandEvent event, String key, String defaultValue) Deprecated.UseSlashCommandEvent.optString(String, String)instead.static net.dv8tion.jda.api.entities.UseroptUser(SlashCommandEvent event, String key) Deprecated.UseSlashCommandEvent.optUser(String)instead.static net.dv8tion.jda.api.entities.UseroptUser(SlashCommandEvent event, String key, net.dv8tion.jda.api.entities.User defaultValue) Deprecated.UseSlashCommandEvent.optUser(String, User)instead.
-
Method Details
-
optString
@Nullable @Deprecated @DeprecatedSince("2.0") @ForRemoval(deadline="2.1") public static String optString(@NotNull SlashCommandEvent event, @NotNull String key) Deprecated.UseSlashCommandEvent.optString(String)instead.Gets the provided Option Key as a String value, or returnsnullif the option cannot be found.- Parameters:
event- The slash command event to get options fromkey- 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) Deprecated.UseSlashCommandEvent.optString(String, String)instead.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 fromkey- The option we wantdefaultValue- 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.UseSlashCommandEvent.optBoolean(String)instead.Gets the provided Option Key as a boolean value, or returnsfalseif the option cannot be found.- Parameters:
event- The slash command event to get options fromkey- 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) Deprecated.UseSlashCommandEvent.optBoolean(String, boolean)instead.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 fromkey- The option we wantdefaultValue- 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.UseSlashCommandEvent.optLong(String)instead.Gets the provided Option Key as a long value, or returns0if the option cannot be found.- Parameters:
event- The slash command event to get options fromkey- 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.UseSlashCommandEvent.optLong(String, long)instead.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 fromkey- The option we wantdefaultValue- 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.UseSlashCommandEvent.optDouble(String)instead.Gets the provided Option Key as a double value, or returns0.0if the option cannot be found.- Parameters:
event- The slash command event to get options fromkey- 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) Deprecated.UseSlashCommandEvent.optDouble(String, double)instead.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 fromkey- The option we wantdefaultValue- 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) Deprecated.UseSlashCommandEvent.optGuildChannel(String)instead.Gets the provided Option Key as a GuildChannel value, or returnsnullif 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 fromkey- 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) Deprecated.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 fromkey- The option we wantdefaultValue- 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.UseSlashCommandEvent.optMember(String)instead.Gets the provided Option Key as a Member value, or returnsnullif 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 fromkey- 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) Deprecated.UseSlashCommandEvent.optMember(String, Member)instead.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 fromkey- The option we wantdefaultValue- 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) Deprecated.UseSlashCommandEvent.optMentionable(String)instead.Gets the provided Option Key as a IMentionable value, or returnsnullif the option cannot be found.- Parameters:
event- The slash command event to get options fromkey- 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) Deprecated.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 fromkey- The option we wantdefaultValue- 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.UseSlashCommandEvent.optRole(String)instead.Gets the provided Option Key as a Role value, or returnsnullif 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 fromkey- 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.UseSlashCommandEvent.optRole(String, Role)instead.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 fromkey- The option we wantdefaultValue- 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.UseSlashCommandEvent.optUser(String)instead.Gets the provided Option Key as a User value, or returnsnullif the option cannot be found.- Parameters:
event- The slash command event to get options fromkey- 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.UseSlashCommandEvent.optUser(String, User)instead.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 fromkey- The option we wantdefaultValue- 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) Deprecated.UseSlashCommandEvent.optMessageChannel(String)instead.Gets the provided Option Key as a MessageChannel value, or returnsnullif the option cannot be found.- Parameters:
event- The slash command event to get options fromkey- 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) Deprecated.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 fromkey- The option we wantdefaultValue- 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.UseSlashCommandEvent.hasOption(String)instead.Will return if the provided key resolves into a provided Option for the SlashCommand.- Parameters:
event- the slash command event to get options fromkey- the option we want- Returns:
- true if the option exists, false otherwise
-
SlashCommandEventmethods instead.