Interface Interaction

    • Method Detail

      • getTypeRaw

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

        @Nonnull
        java.lang.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
      • 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
      • getChannel

        @Nullable
        AbstractChannel 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
      • getHook

        @Nonnull
        InteractionHook getHook()
        The InteractionHook which can be used to send deferred replies or followup messages.
        Returns:
        The interaction hook
        Throws:
        java.lang.UnsupportedOperationException - If this interaction does not support deferred replies and followup messages
      • isAcknowledged

        boolean isAcknowledged()
        Whether this interaction has already been acknowledged.
        Both deferReply() and reply(String) acknowledge an interaction. Each interaction can only be acknowledged once.
        Returns:
        True, if this interaction has already been acknowledged
      • deferReply

        @Nonnull
        @CheckReturnValue
        default ReplyAction deferReply​(boolean ephemeral)
        Acknowledge this interaction and defer the reply to a later time.
        This will send a <Bot> is thinking... message in chat that will be updated later through either InteractionHook.editOriginal(String) or WebhookClient.sendMessage(String).

        You can use deferReply() or deferReply(false) to send a non-ephemeral deferred reply. If your initial deferred message is ephemeral it cannot be made non-ephemeral later. Your first message to the InteractionHook will inherit whether the message is ephemeral or not from this deferred reply.

        You only have 3 seconds to acknowledge an interaction!
        When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

        Use reply(String) to reply directly.

        Ephemeral messages have some limitations and will be removed once the user restarts their client.
        When a message is ephemeral, it will only be visible to the user that used the interaction.
        Limitations:

        • Cannot be deleted by the bot
        • Cannot contain any files/attachments
        • Cannot be reacted to
        • Cannot be retrieved
        Parameters:
        ephemeral - True, if this message should only be visible to the interaction user
        Returns:
        ReplyAction
      • reply

        @Nonnull
        @CheckReturnValue
        default ReplyAction reply​(@Nonnull
                                  Message message)
        Reply to this interaction and acknowledge it.
        This will send a reply message for this interaction. You can use setEphemeral(true) to only let the target user see the message. Replies are non-ephemeral by default.

        You only have 3 seconds to acknowledge an interaction!
        When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

        If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use deferReply() instead.

        Parameters:
        message - The message to send
        Returns:
        ReplyAction
        Throws:
        java.lang.IllegalArgumentException - If null is provided
      • reply

        @Nonnull
        @CheckReturnValue
        default ReplyAction reply​(@Nonnull
                                  java.lang.String content)
        Reply to this interaction and acknowledge it.
        This will send a reply message for this interaction. You can use setEphemeral(true) to only let the target user see the message. Replies are non-ephemeral by default.

        You only have 3 seconds to acknowledge an interaction!
        When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

        If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use deferReply() instead.

        Parameters:
        content - The message content to send
        Returns:
        ReplyAction
        Throws:
        java.lang.IllegalArgumentException - If null is provided or the content is empty or longer than Message.MAX_CONTENT_LENGTH
      • replyEmbeds

        @Nonnull
        @CheckReturnValue
        default ReplyAction replyEmbeds​(@Nonnull
                                        java.util.Collection<? extends MessageEmbed> embeds)
        Reply to this interaction and acknowledge it.
        This will send a reply message for this interaction. You can use setEphemeral(true) to only let the target user see the message. Replies are non-ephemeral by default.

        You only have 3 seconds to acknowledge an interaction!
        When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

        If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use deferReply() instead.

        Parameters:
        embeds - The MessageEmbeds to send
        Returns:
        ReplyAction
        Throws:
        java.lang.IllegalArgumentException - If null is provided
      • replyEmbeds

        @Nonnull
        @CheckReturnValue
        default ReplyAction replyEmbeds​(@Nonnull
                                        MessageEmbed embed,
                                        @Nonnull
                                        MessageEmbed... embeds)
        Reply to this interaction and acknowledge it.
        This will send a reply message for this interaction. You can use setEphemeral(true) to only let the target user see the message. Replies are non-ephemeral by default.

        You only have 3 seconds to acknowledge an interaction!
        When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

        If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use deferReply() instead.

        Parameters:
        embed - The message embed to send
        embeds - Any additional embeds to send
        Returns:
        ReplyAction
        Throws:
        java.lang.IllegalArgumentException - If null is provided
      • replyFormat

        @Nonnull
        @CheckReturnValue
        default ReplyAction replyFormat​(@Nonnull
                                        java.lang.String format,
                                        @Nonnull
                                        java.lang.Object... args)
        Reply to this interaction and acknowledge it.
        This will send a reply message for this interaction. You can use setEphemeral(true) to only let the target user see the message. Replies are non-ephemeral by default.

        You only have 3 seconds to acknowledge an interaction!
        When the acknowledgement is sent after the interaction expired, you will receive ErrorResponse.UNKNOWN_INTERACTION.

        If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use deferReply() instead.

        Parameters:
        format - Format string for the message content
        args - Format arguments for the content
        Returns:
        ReplyAction
        Throws:
        java.lang.IllegalArgumentException - If the format string is null or the resulting content is longer than Message.MAX_CONTENT_LENGTH
      • getJDA

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