Class YCommandInteractionPayload
- Direct Known Subclasses:
YCommandInteraction
-
Constructor Summary
ConstructorsConstructorDescriptionYCommandInteractionPayload(net.dv8tion.jda.api.interactions.callbacks.IReplyCallback callback, net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload commandInteractionPayload) -
Method Summary
Modifier and TypeMethodDescription@Nullable net.dv8tion.jda.api.entities.ChannelThe channel this interaction happened in.@NotNull net.dv8tion.jda.api.entities.ChannelTypeTheChannelTypefor the channel this interaction came from.@NotNull StringThe command id
This is the id generated when a command is created viaGuild.updateCommands()or similar.longThe command idnet.dv8tion.jda.api.interactions.commands.CommandInteractionPayload@NotNull String@NotNull StringGets the display string for this command.net.dv8tion.jda.api.interactions.commands.Command.TypeTheTypeof command this interaction is for.@Nullable YGuildgetGuild()TheYGuildthis interaction happened in.@NotNull net.dv8tion.jda.api.entities.GuildChannelTheGuildChannelthis interaction happened in.@NotNull LocaleReturns the preferred language of the Guild.@NotNull StringgetId()The Snowflake id of this entity.longThe Snowflake id of this entity.@NotNull net.dv8tion.jda.api.JDAgetJDA()Returns theJDAinstance of this interaction@Nullable YMemberTheYMemberwho caused this interaction.@NotNull net.dv8tion.jda.api.entities.MessageChannelTheMessageChannelthis interaction happened in.@NotNull StringgetName()The command name.@NotNull net.dv8tion.jda.api.entities.NewsChannelTheNewsChannelthis interaction happened in.@Nullable YusufOptionMappingFinds the first option with the specified name.<T> TgetOption(String name, Function<? super YusufOptionMapping, ? extends T> resolver) Finds the first option with the specified name.<T> TgetOption(String name, Supplier<? extends T> fallback, Function<? super YusufOptionMapping, ? extends T> resolver) Finds the first option with the specified name.<T> TgetOption(String name, T fallback, Function<? super YusufOptionMapping, ? extends T> resolver) Finds the first option with the specified name.The options provided by the user when this command was executed.getOptionsByName(@NotNull String name) Gets all options for the specified name.getOptionsByType(@NotNull net.dv8tion.jda.api.interactions.commands.OptionType type) Gets all options for the specified type.@NotNull net.dv8tion.jda.api.entities.PrivateChannelThePrivateChannelthis interaction happened in.@Nullable StringThe subcommand group name.@Nullable StringThe subcommand name.@NotNull net.dv8tion.jda.api.entities.TextChannelTheTextChannelthis interaction happened in.@NotNull net.dv8tion.jda.api.entities.ThreadChannelTheThreadChannelthis interaction happened in.@NotNull OffsetDateTimeThe time this entity was created.@NotNull StringgetToken()The interaction token used for responding to an interaction.@NotNull net.dv8tion.jda.api.interactions.InteractionTypegetType()TheInteractionTypefor this interaction.intThe raw interaction type.@NotNull YUsergetUser()TheYUserwho caused this interaction.@NotNull LocaleReturns the selected language of the invoking user.@NotNull net.dv8tion.jda.api.entities.VoiceChannelTheVoiceChannelthis interaction happened in.booleanWhether this interaction has already been acknowledged.booleanWhether this interaction came from aYGuild.Methods inherited from class io.github.yusufsdiscordbot.yusufsdiscordcore.bot.interaction.YReplyCallback
deferReply, deferReply, getCallback, getHook, reply, reply, replyEmbeds, replyEmbeds, replyFile, replyFile, replyFile, replyFile, replyFormat, replyQueuedEmbed, replyQueuedEphemeral, replyQueuedEphemeralEmbed, replyQueuedMessage
-
Constructor Details
-
YCommandInteractionPayload
public YCommandInteractionPayload(net.dv8tion.jda.api.interactions.callbacks.IReplyCallback callback, net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload commandInteractionPayload)
-
-
Method Details
-
getCommandInteractionPayload
public net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload getCommandInteractionPayload() -
getCommandType
@NotNull public net.dv8tion.jda.api.interactions.commands.Command.Type getCommandType()TheTypeof command this interaction is for.- Returns:
- The command type
-
getName
The command name.
This can be useful for abstractions.Note that commands can have these following structures:
/name subcommandGroup subcommandName/name subcommandName/name
You can use
getCommandPath()to simplify your checks.- Returns:
- The command name
-
getSubcommandName
The subcommand name.
This can be useful for abstractions.Note that commands can have these following structures:
/name subcommandGroup subcommandName/name subcommandName/name
You can use
getCommandPath()to simplify your checks.- Returns:
- The subcommand name, or null if this is not a subcommand
-
getSubcommandGroup
The subcommand group name.
This can be useful for abstractions.Note that commands can have these following structures:
/name subcommandGroup subcommandName/name subcommandName/name
You can use
getCommandPath()to simplify your checks.- Returns:
- The subcommand group name, or null if this is not a subcommand group
-
getCommandIdLong
public long getCommandIdLong()The command id- Returns:
- The command id
-
getOption
Finds the first option with the specified name.- Parameters:
name- The option name- Returns:
- The option with the provided name, or null if that option is not provided
- Throws:
IllegalArgumentException- If the name is null
-
getOptions
The options provided by the user when this command was executed.
Each option has a name and value.- Returns:
- The options passed for this command
-
getOptionsByName
Gets all options for the specified name.- Parameters:
name- The option name- Returns:
- The list of options
- Throws:
IllegalArgumentException- If the provided name is null- See Also:
-
getOptionsByType
@Nonnull public List<YusufOptionMapping> getOptionsByType(@NotNull @NotNull net.dv8tion.jda.api.interactions.commands.OptionType type) Gets all options for the specified type.- Parameters:
type- The option type- Returns:
- The list of options
- Throws:
IllegalArgumentException- If the provided type is null
-
getCommandPath
Combination ofgetName(),getSubcommandGroup(), andgetSubcommandName().
This will format the command into a path such asmod/mutewheremodwould be thegetName()andmutethegetSubcommandName().Examples:
/mod ban -> "mod/ban"/admin config owner -> "admin/config/owner"/ban -> "ban"
- Returns:
- The command path
-
getCommandString
Gets the display string for this command.
This is similar to the string you see when clicking the interaction name in the client. For non-slash command types, this simply returnsgetName()instead.Example return for an echo command:
/say echo phrase: Say this- Returns:
- The display string for this command
-
getOption
@Nullable public <T> T getOption(@Nonnull String name, @Nonnull Function<? super YusufOptionMapping, ? extends T> resolver) Finds the first option with the specified name.
A resolver is used to get the value if the option is provided. If no option is provided for the given name, this will simply return null instead. You can usegetOption(String, Object, Function)to provide a fallback for missing options.For
CommandAutoCompleteInteraction, this might be incomplete and unvalidated. Auto-complete interactions happen on incomplete command inputs and are not validated.Example
You can understand this as a shortcut for these lines of code:{ @code OptionMapping opt = event.getOption("reason"); String reason = opt == null ? null : opt.getAsString(); }Which can be written with this resolver as:String reason = event.getOption("reason", OptionMapping::getAsString);- Type Parameters:
T- The type of the resolved option value- Parameters:
name- The option nameresolver- The mapping resolver function to use if there is a mapping available, the provided mapping will never be null!- Returns:
- The resolved option with the provided name, or null if that option is not provided
- Throws:
IllegalArgumentException- If the name or resolver is null- See Also:
-
getOption
public <T> T getOption(@Nonnull String name, @Nullable T fallback, @Nonnull Function<? super YusufOptionMapping, ? extends T> resolver) Finds the first option with the specified name.
A resolver is used to get the value if the option is provided. If no option is provided for the given name, this will simply return your provided fallback instead. You can usegetOption(String, Function)to fall back tonull.For
CommandAutoCompleteInteraction, this might be incomplete and unvalidated. Auto-complete interactions happen on incomplete command inputs and are not validated.Example
You can understand this as a shortcut for these lines of code:{ @code OptionMapping opt = event.getOption("reason"); String reason = opt == null ? "ban by mod" : opt.getAsString(); }Which can be written with this resolver as:String reason = event.getOption("reason", "ban by mod", OptionMapping::getAsString);- Type Parameters:
T- The type of the resolved option value- Parameters:
name- The option namefallback- The fallback to use if the option is not provided, meaninggetOption(String)returns nullresolver- The mapping resolver function to use if there is a mapping available, the provided mapping will never be null!- Returns:
- The resolved option with the provided name, or
fallbackif that option is not provided - Throws:
IllegalArgumentException- If the name or resolver is null- See Also:
-
getOption
public <T> T getOption(@Nonnull String name, @Nullable Supplier<? extends T> fallback, @Nonnull Function<? super YusufOptionMapping, ? extends T> resolver) Finds the first option with the specified name.
A resolver is used to get the value if the option is provided. If no option is provided for the given name, this will simply return your provided fallback instead. You can usegetOption(String, Function)to fall back tonull.For
CommandAutoCompleteInteraction, this might be incomplete and unvalidated. Auto-complete interactions happen on incomplete command inputs and are not validated.Example
You can understand this as a shortcut for these lines of code:{ @code OptionMapping opt = event.getOption("reason"); String reason = opt == null ? context.getFallbackReason() : opt.getAsString(); }Which can be written with this resolver as:String reason = event.getOption("reason", context::getFallbackReason , OptionMapping::getAsString);- Type Parameters:
T- The type of the resolved option value- Parameters:
name- The option namefallback- The fallback supplier to use if the option is not provided, meaninggetOption(String)returns nullresolver- The mapping resolver function to use if there is a mapping available, the provided mapping will never be null!- Returns:
- The resolved option with the provided name, or
fallbackif that option is not provided - Throws:
IllegalArgumentException- If the name or resolver is null- See Also:
-
getCommandId
The command id
This is the id generated when a command is created viaGuild.updateCommands()or similar.It is usually preferred to discriminate commands by the
command namesinstead.- Returns:
- The command id
-
getTypeRaw
public int getTypeRaw()The raw interaction type.
It is recommended to usegetType()instead.- Returns:
- The raw interaction type
-
getType
@NotNull public @NotNull net.dv8tion.jda.api.interactions.InteractionType getType()TheInteractionTypefor this interaction.- Returns:
- The
InteractionTypeorInteractionType.UNKNOWN
-
getToken
The interaction token used for responding to an interaction.- Returns:
- The interaction token
-
getGuild
TheYGuildthis interaction happened in.
This is null in direct messages.- Returns:
- The
YGuildor null
-
isFromGuild
public boolean isFromGuild()- Returns:
- True, if this interaction happened in a guild
-
getChannelType
@NotNull public @NotNull net.dv8tion.jda.api.entities.ChannelType getChannelType()TheChannelTypefor the channel this interaction came from.
IfgetChannel()is null, this returnsChannelType.UNKNOWN.- Returns:
- The
ChannelType
-
getUser
TheYUserwho caused this interaction.- Returns:
- The
YUser
-
getMember
TheYMemberwho caused this interaction.
This is null if the interaction is not from a guild.- Returns:
- The
YMember
-
getChannel
@Nullable public @Nullable net.dv8tion.jda.api.entities.Channel getChannel()The channel this interaction happened in.
This is currently never null, but might be nullable in the future.- Returns:
- The channel or null if this interaction is not from a channel context
-
isAcknowledged
public boolean isAcknowledged()Whether this interaction has already been acknowledged.
Each interaction can only be acknowledged once.- Returns:
- True, if this interaction has already been acknowledged
-
getGuildChannel
@NotNull public @NotNull net.dv8tion.jda.api.entities.GuildChannel getGuildChannel()TheGuildChannelthis interaction happened in.
IfgetChannelType()is not a guild type, this throwsIllegalStateException!- Returns:
- The
GuildChannel - Throws:
IllegalStateException- IfgetChannel()is not a guild channel
-
getMessageChannel
@NotNull public @NotNull net.dv8tion.jda.api.entities.MessageChannel getMessageChannel()TheMessageChannelthis interaction happened in.
IfgetChannelType()is not a message channel type, this throwsIllegalStateException!- Returns:
- The
MessageChannel - Throws:
IllegalStateException- IfgetChannel()is not a message channel
-
getTextChannel
@NotNull public @NotNull net.dv8tion.jda.api.entities.TextChannel getTextChannel()TheTextChannelthis interaction happened in.
IfgetChannelType()is notChannelType.TEXT, this throwsIllegalStateException!- Returns:
- The
TextChannel - Throws:
IllegalStateException- IfgetChannel()is not a text channel
-
getNewsChannel
@NotNull public @NotNull net.dv8tion.jda.api.entities.NewsChannel getNewsChannel()TheNewsChannelthis interaction happened in.
IfgetChannelType()is notChannelType.NEWS, this throwsIllegalStateException!- Returns:
- The
NewsChannel - Throws:
IllegalStateException- IfgetChannel()is not news channel
-
getVoiceChannel
@NotNull public @NotNull net.dv8tion.jda.api.entities.VoiceChannel getVoiceChannel()TheVoiceChannelthis interaction happened in.
IfgetChannelType()is notChannelType.VOICE, this throwsIllegalStateException!- Returns:
- The
VoiceChannel - Throws:
IllegalStateException- IfgetChannel()is not a voice channel
-
getPrivateChannel
@NotNull public @NotNull net.dv8tion.jda.api.entities.PrivateChannel getPrivateChannel()ThePrivateChannelthis interaction happened in.
IfgetChannelType()is notChannelType.PRIVATE, this throwsIllegalStateException!- Returns:
- The
PrivateChannel - Throws:
IllegalStateException- IfgetChannel()is not a private channel
-
getThreadChannel
@NotNull public @NotNull net.dv8tion.jda.api.entities.ThreadChannel getThreadChannel()TheThreadChannelthis interaction happened in.
IfgetChannelType()is notChannelType.isThread(), this throwsIllegalStateException!- Returns:
- The
ThreadChannel - Throws:
IllegalStateException- IfgetChannel()is not a thread channel
-
getUserLocale
Returns the selected language of the invoking user.- Returns:
- The language of the invoking user
-
getGuildLocale
Returns the preferred language of the Guild.
This is identical togetGuild().getLocale().- Returns:
- The preferred language of the Guild
- Throws:
IllegalStateException- If this interaction is not from a guild. (SeeisFromGuild())
-
getJDA
@NotNull public @NotNull net.dv8tion.jda.api.JDA getJDA()Returns theJDAinstance of this interaction- Returns:
- the corresponding JDA instance
-
getId
The Snowflake id of this entity. This is unique to every entity and will never change.- Returns:
- Never-null String containing the Id.
-
getIdLong
public long getIdLong()The Snowflake id of this entity. This is unique to every entity and will never change.- Returns:
- Long containing the Id.
-
getTimeCreated
The time this entity was created. Calculated through the Snowflake ingetIdLong().- Returns:
- OffsetDateTime - Time this entity was created at.
- See Also:
-
TimeUtil.getTimeCreated(long)
-