Interface Interaction

All Superinterfaces:
ISnowflake
All Known Subinterfaces:
ButtonInteraction, CommandAutoCompleteInteraction, CommandInteraction, CommandInteractionPayload, ComponentInteraction, ContextInteraction<T>, EntitySelectInteraction, IAutoCompleteCallback, IDeferrableCallback, IMessageEditCallback, IModalCallback, IPremiumRequiredReplyCallback, IReplyCallback, MessageContextInteraction, ModalInteraction, SelectMenuInteraction<T,S>, SlashCommandInteraction, StringSelectInteraction, UserContextInteraction
All Known Implementing Classes:
ButtonInteractionEvent, CommandAutoCompleteInteractionEvent, EntitySelectInteractionEvent, GenericAutoCompleteInteractionEvent, GenericCommandInteractionEvent, GenericComponentInteractionCreateEvent, GenericContextInteractionEvent, GenericInteractionCreateEvent, GenericSelectMenuInteractionEvent, MessageContextInteractionEvent, ModalInteractionEvent, SlashCommandInteractionEvent, StringSelectInteractionEvent, UserContextInteractionEvent

public interface Interaction extends ISnowflake
Abstract representation for any kind of Discord interaction.
This includes things such as Slash-Commands, Buttons or Modals.

To properly handle an interaction you must acknowledge it. Each interaction has different callbacks which acknowledge the interaction. These are added by the individual I...Callback interfaces:

Once the interaction is acknowledged, you can not reply with these methods again. If the interaction is a deferrable, you can use IDeferrableCallback.getHook() to send additional messages or update the original reply. When using IReplyCallback.deferReply() the first message sent to the InteractionHook will be identical to using InteractionHook.editOriginal(String). You must decide whether your reply will be ephemeral or not before calling IReplyCallback.deferReply(). So design your code flow with that in mind!

You can only acknowledge an interaction once! Any additional calls to reply/deferReply will result in exceptions. You can use isAcknowledged() to check whether the interaction has been acknowledged already.

  • Method Details

    • getTypeRaw

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

      @Nonnull default InteractionType getType()
      The InteractionType for this interaction.
      Returns:
      The InteractionType or InteractionType.UNKNOWN
    • getToken

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

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

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

      @Nonnull default ChannelType getChannelType()
      The ChannelType for the channel this interaction came from.
      If getChannel() is null, this returns ChannelType.UNKNOWN.
      Returns:
      The ChannelType
    • getUser

      @Nonnull User getUser()
      The User who caused this interaction.
      Returns:
      The User
    • getMember

      @Nullable Member getMember()
      The Member who caused this interaction.
      This is null if the interaction is not from a guild.
      Returns:
      The Member
    • isAcknowledged

      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
    • getChannel

      @Nullable Channel getChannel()
      The channel this interaction happened in.
      Returns:
      The channel or null if the channel is not provided
    • getChannelIdLong

      long getChannelIdLong()
      The ID of the channel this interaction happened in.
      This might be 0 if no channel context is provided in future interaction types.
      Returns:
      The channel ID, or 0 if no channel context is provided
    • getChannelId

      @Nullable default String getChannelId()
      The ID of the channel this interaction happened in.
      This might be null if no channel context is provided in future interaction types.
      Returns:
      The channel ID, or null if no channel context is provided
    • getGuildChannel

      @Nonnull default 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

      @Nonnull default 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
    • getUserLocale

      @Nonnull DiscordLocale getUserLocale()
      Returns the selected language of the invoking user.
      Returns:
      The language of the invoking user
    • getGuildLocale

      @Nonnull default DiscordLocale 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())
    • getEntitlements

      @Nonnull List<Entitlement> getEntitlements()
      Returns the list of entitlements for the current guild and user.
      If this interaction is not from a guild, it will only contain entitlements of the user.
      Returns:
      The List of Entitlement
    • getJDA

      @Nonnull JDA getJDA()
      Returns the JDA instance of this interaction
      Returns:
      the corresponding JDA instance