Class YCommandInteractionPayload

java.lang.Object
io.github.yusufsdiscordbot.yusufsdiscordcore.bot.interaction.YReplyCallback
io.github.yusufsdiscordbot.yusufsdiscordcore.bot.interaction.YCommandInteractionPayload
Direct Known Subclasses:
YCommandInteraction

public class YCommandInteractionPayload extends YReplyCallback
  • 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()
      The Type of command this interaction is for.
      Returns:
      The command type
    • getName

      @NotNull public @NotNull String 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

      @Nullable public @Nullable String 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

      @Nullable public @Nullable String 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

      @Nullable public @Nullable YusufOptionMapping getOption(@Nonnull String name)
      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

      @Nonnull public List<YusufOptionMapping> 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

      @Nonnull public List<YusufOptionMapping> getOptionsByName(@NotNull @NotNull String name)
      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

      @NotNull public @NotNull String getCommandPath()
      Combination of getName(), getSubcommandGroup(), and getSubcommandName().
      This will format the command into a path such as mod/mute where mod would be the getName() and mute the getSubcommandName().

      Examples:

      • /mod ban -> "mod/ban"
      • /admin config owner -> "admin/config/owner"
      • /ban -> "ban"
      Returns:
      The command path
    • getCommandString

      @NotNull public @NotNull String 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 returns getName() 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 use getOption(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 name
      resolver - 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 use getOption(String, Function) to fall back to null.

      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 name
      fallback - The fallback to use if the option is not provided, meaning getOption(String) returns null
      resolver - 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 fallback 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 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 use getOption(String, Function) to fall back to null.

      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 name
      fallback - The fallback supplier to use if the option is not provided, meaning getOption(String) returns null
      resolver - 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 fallback if that option is not provided
      Throws:
      IllegalArgumentException - If the name or resolver is null
      See Also:
    • getCommandId

      @NotNull public @NotNull String getCommandId()
      The command id
      This is the id generated when a command is created via Guild.updateCommands() or similar.

      It is usually preferred to discriminate commands by the command names instead.

      Returns:
      The command id
    • getTypeRaw

      public int getTypeRaw()
      The raw interaction type.
      It is recommended to use getType() instead.
      Returns:
      The raw interaction type
    • getType

      @NotNull public @NotNull net.dv8tion.jda.api.interactions.InteractionType getType()
      The InteractionType for this interaction.
      Returns:
      The InteractionType or InteractionType.UNKNOWN
    • getToken

      @NotNull public @NotNull String getToken()
      The interaction token used for responding to an interaction.
      Returns:
      The interaction token
    • getGuild

      @Nullable public @Nullable YGuild getGuild()
      The YGuild this interaction happened in.
      This is null in direct messages.
      Returns:
      The YGuild or null
    • isFromGuild

      public boolean isFromGuild()
      Whether this interaction came from a YGuild.
      This is identical to getGuild() != null
      Returns:
      True, if this interaction happened in a guild
    • getChannelType

      @NotNull public @NotNull net.dv8tion.jda.api.entities.ChannelType getChannelType()
      The ChannelType for the channel this interaction came from.
      If getChannel() is null, this returns ChannelType.UNKNOWN.
      Returns:
      The ChannelType
    • getUser

      @NotNull public @NotNull YUser getUser()
      The YUser who caused this interaction.
      Returns:
      The YUser
    • getMember

      @Nullable public @Nullable YMember getMember()
      The YMember who 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()
      The GuildChannel this interaction happened in.
      If getChannelType() is not a guild type, this throws IllegalStateException!
      Returns:
      The GuildChannel
      Throws:
      IllegalStateException - If getChannel() is not a guild channel
    • getMessageChannel

      @NotNull public @NotNull net.dv8tion.jda.api.entities.MessageChannel getMessageChannel()
      The MessageChannel this interaction happened in.
      If getChannelType() is not a message channel type, this throws IllegalStateException!
      Returns:
      The MessageChannel
      Throws:
      IllegalStateException - If getChannel() is not a message channel
    • getTextChannel

      @NotNull public @NotNull net.dv8tion.jda.api.entities.TextChannel getTextChannel()
      The TextChannel this interaction happened in.
      If getChannelType() is not ChannelType.TEXT, this throws IllegalStateException!
      Returns:
      The TextChannel
      Throws:
      IllegalStateException - If getChannel() is not a text channel
    • getNewsChannel

      @NotNull public @NotNull net.dv8tion.jda.api.entities.NewsChannel getNewsChannel()
      The NewsChannel this interaction happened in.
      If getChannelType() is not ChannelType.NEWS, this throws IllegalStateException!
      Returns:
      The NewsChannel
      Throws:
      IllegalStateException - If getChannel() is not news channel
    • getVoiceChannel

      @NotNull public @NotNull net.dv8tion.jda.api.entities.VoiceChannel getVoiceChannel()
      The VoiceChannel this interaction happened in.
      If getChannelType() is not ChannelType.VOICE, this throws IllegalStateException!
      Returns:
      The VoiceChannel
      Throws:
      IllegalStateException - If getChannel() is not a voice channel
    • getPrivateChannel

      @NotNull public @NotNull net.dv8tion.jda.api.entities.PrivateChannel getPrivateChannel()
      The PrivateChannel this interaction happened in.
      If getChannelType() is not ChannelType.PRIVATE, this throws IllegalStateException!
      Returns:
      The PrivateChannel
      Throws:
      IllegalStateException - If getChannel() is not a private channel
    • getThreadChannel

      @NotNull public @NotNull net.dv8tion.jda.api.entities.ThreadChannel getThreadChannel()
      The ThreadChannel this interaction happened in.
      If getChannelType() is not ChannelType.isThread(), this throws IllegalStateException!
      Returns:
      The ThreadChannel
      Throws:
      IllegalStateException - If getChannel() is not a thread channel
    • getUserLocale

      @NotNull public @NotNull Locale getUserLocale()
      Returns the selected language of the invoking user.
      Returns:
      The language of the invoking user
    • getGuildLocale

      @NotNull public @NotNull Locale getGuildLocale()
      Returns the preferred language of the Guild.
      This is identical to getGuild().getLocale().
      Returns:
      The preferred language of the Guild
      Throws:
      IllegalStateException - If this interaction is not from a guild. (See isFromGuild())
    • getJDA

      @NotNull public @NotNull net.dv8tion.jda.api.JDA getJDA()
      Returns the JDA instance of this interaction
      Returns:
      the corresponding JDA instance
    • getId

      @NotNull public @NotNull String 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

      @NotNull public @NotNull OffsetDateTime getTimeCreated()
      The time this entity was created. Calculated through the Snowflake in getIdLong().
      Returns:
      OffsetDateTime - Time this entity was created at.
      See Also:
      • TimeUtil.getTimeCreated(long)