Interface InteractionHook

    • Method Detail

      • getInteraction

        @Nonnull
        Interaction getInteraction()
        The interaction attached to this hook.
        Returns:
        The Interaction
      • getExpirationTimestamp

        default long getExpirationTimestamp()
        The unix millisecond timestamp for the expiration of this interaction hook.
        An interaction hook expires after 15 minutes of its creation.
        Returns:
        The timestamp in millisecond precision
        See Also:
        System.currentTimeMillis(), isExpired()
      • isExpired

        default boolean isExpired()
        Whether this interaction has expired.
        An interaction hook is only valid for 15 minutes.
        Returns:
        True, if this interaction hook has expired
        See Also:
        getExpirationTimestamp()
      • setEphemeral

        @Nonnull
        InteractionHook setEphemeral​(boolean ephemeral)
        Whether messages sent from this interaction hook should be ephemeral by default.
        This does not affect message updates, including deferred replies sent with sendMessage(...) methods.
        When a message is ephemeral, it will only be visible to the user that used the interaction.

        Ephemeral messages have some limitations and will be removed once the user restarts their client.
        Limitations:

        • Cannot be deleted by the bot
        • Cannot contain any files/attachments
        • Cannot be reacted to
        • Cannot be retrieved
        Parameters:
        ephemeral - True if messages should be ephemeral
        Returns:
        The same interaction hook instance
      • getJDA

        @Nonnull
        JDA getJDA()
        The JDA instance for this interaction
        Returns:
        The JDA instance
      • retrieveOriginal

        @Nonnull
        @CheckReturnValue
        RestAction<Message> retrieveOriginal()
        Retrieves the original reply to this interaction.
        This doesn't work for ephemeral messages and will always cause an unknown message error response.
        Returns:
        RestAction - Type: Message
      • editOriginal

        @Nonnull
        @CheckReturnValue
        default WebhookMessageUpdateAction<Message> editOriginal​(@Nonnull
                                                                 java.io.InputStream data,
                                                                 @Nonnull
                                                                 java.lang.String name,
                                                                 @Nonnull
                                                                 AttachmentOption... options)
        Edit the source message sent by this interaction.
        For ComponentInteraction.editComponents(Collection) and ComponentInteraction.deferEdit() this will be the message the components are attached to. For Interaction.deferReply() and Interaction.reply(String) this will be the reply message instead.
        The provided file will be appended to the message. You cannot delete or edit existing files on a message.

        This method will be delayed until the interaction is acknowledged.

        Uploading images with Embeds
        When uploading an image you can reference said image using the specified filename as URI attachment://filename.ext.

        Example

        
         WebhookClient hook; // = reference of a WebhookClient such as interaction.getHook()
         EmbedBuilder embed = new EmbedBuilder();
         InputStream file = new FileInputStream("image.png"); // the name in your file system can be different from the name used in discord
         embed.setImage("attachment://cat.png") // we specify this in sendFile as "cat.png"
              .setDescription("This is a cute cat :3");
         hook.editOriginal(file, "cat.png").setEmbeds(embed.build()).queue();
         

        Possible ErrorResponses include:

        • UNKNOWN_WEBHOOK
          The webhook is no longer available, either it was deleted or in case of interactions it expired.
        • UNKNOWN_MESSAGE
          The message for that id does not exist
        Parameters:
        data - The InputStream data to upload to the webhook.
        name - The file name that should be sent to discord
        Refer to the documentation for WebhookClient.sendFile(java.io.File, String, AttachmentOption...) for information about this parameter.
        options - Possible options to apply to this attachment, such as marking it as spoiler image
        Returns:
        WebhookMessageUpdateAction
        Throws:
        java.lang.IllegalArgumentException - If the provided data, or filename is null.
      • editOriginal

        @Nonnull
        @CheckReturnValue
        default WebhookMessageUpdateAction<Message> editOriginal​(@Nonnull
                                                                 java.io.File file,
                                                                 @Nonnull
                                                                 AttachmentOption... options)
        Edit the source message sent by this interaction.
        For ComponentInteraction.editComponents(Collection) and ComponentInteraction.deferEdit() this will be the message the components are attached to. For Interaction.deferReply() and Interaction.reply(String) this will be the reply message instead.
        The provided file will be appended to the message. You cannot delete or edit existing files on a message.

        This method will be delayed until the interaction is acknowledged.

        This is a shortcut to editOriginal(java.io.File, String, AttachmentOption...) by way of using File.getName().

        editOriginal(file, file.getName())

        Uploading images with Embeds
        When uploading an image you can reference said image using the specified filename as URI attachment://filename.ext.

        Example

        
         WebhookClient hook; // = reference of a WebhookClient such as interaction.getHook()
         EmbedBuilder embed = new EmbedBuilder();
         File file = new File("image.png"); // the name in your file system can be different from the name used in discord
         embed.setImage("attachment://cat.png") // we specify this in sendFile as "cat.png"
              .setDescription("This is a cute cat :3");
         hook.editOriginal(file, "cat.png").setEmbeds(embed.build()).queue();
         

        Possible ErrorResponses include:

        • UNKNOWN_WEBHOOK
          The webhook is no longer available, either it was deleted or in case of interactions it expired.
        • UNKNOWN_MESSAGE
          The message for that id does not exist
        Parameters:
        file - The File data to upload to the webhook.
        options - Possible options to apply to this attachment, such as marking it as spoiler image
        Returns:
        WebhookMessageUpdateAction
        Throws:
        java.lang.IllegalArgumentException - If the provided file is null.
      • editOriginal

        @Nonnull
        @CheckReturnValue
        default WebhookMessageUpdateAction<Message> editOriginal​(@Nonnull
                                                                 java.io.File file,
                                                                 @Nonnull
                                                                 java.lang.String name,
                                                                 @Nonnull
                                                                 AttachmentOption... options)
        Edit the source message sent by this interaction.
        For ComponentInteraction.editComponents(Collection) and ComponentInteraction.deferEdit() this will be the message the components are attached to. For Interaction.deferReply() and Interaction.reply(String) this will be the reply message instead.
        The provided file will be appended to the message. You cannot delete or edit existing files on a message.

        This method will be delayed until the interaction is acknowledged.

        Uploading images with Embeds
        When uploading an image you can reference said image using the specified filename as URI attachment://filename.ext.

        Example

        
         WebhookClient hook; // = reference of a WebhookClient such as interaction.getHook()
         EmbedBuilder embed = new EmbedBuilder();
         File file = new File("image.png"); // the name in your file system can be different from the name used in discord
         embed.setImage("attachment://cat.png") // we specify this in sendFile as "cat.png"
              .setDescription("This is a cute cat :3");
         hook.editOriginal(file, "cat.png").setEmbeds(embed.build()).queue();
         

        Possible ErrorResponses include:

        • UNKNOWN_WEBHOOK
          The webhook is no longer available, either it was deleted or in case of interactions it expired.
        • UNKNOWN_MESSAGE
          The message for that id does not exist
        Parameters:
        file - The File data to upload to the webhook.
        name - The file name that should be sent to discord
        Refer to the documentation for WebhookClient.sendFile(java.io.File, String, AttachmentOption...) for information about this parameter.
        options - Possible options to apply to this attachment, such as marking it as spoiler image
        Returns:
        WebhookMessageUpdateAction
        Throws:
        java.lang.IllegalArgumentException - If the provided file or filename is null.
      • editOriginal

        @Nonnull
        @CheckReturnValue
        default WebhookMessageUpdateAction<Message> editOriginal​(@Nonnull
                                                                 byte[] data,
                                                                 @Nonnull
                                                                 java.lang.String name,
                                                                 @Nonnull
                                                                 AttachmentOption... options)
        Edit the source message sent by this interaction.
        For ComponentInteraction.editComponents(Collection) and ComponentInteraction.deferEdit() this will be the message the components are attached to. For Interaction.deferReply() and Interaction.reply(String) this will be the reply message instead.
        The provided file will be appended to the message. You cannot delete or edit existing files on a message.

        This method will be delayed until the interaction is acknowledged.

        Uploading images with Embeds
        When uploading an image you can reference said image using the specified filename as URI attachment://filename.ext.

        Example

        
         WebhookClient hook; // = reference of a WebhookClient such as interaction.getHook()
         EmbedBuilder embed = new EmbedBuilder();
         InputStream file = new FileInputStream("image.png"); // the name in your file system can be different from the name used in discord
         embed.setImage("attachment://cat.png") // we specify this in sendFile as "cat.png"
              .setDescription("This is a cute cat :3");
         hook.editOriginal(file, "cat.png").setEmbeds(embed.build()).queue();
         

        Possible ErrorResponses include:

        • UNKNOWN_WEBHOOK
          The webhook is no longer available, either it was deleted or in case of interactions it expired.
        • UNKNOWN_MESSAGE
          The message for that id does not exist
        Parameters:
        data - The InputStream data to upload to the webhook.
        name - The file name that should be sent to discord
        Refer to the documentation for WebhookClient.sendFile(java.io.File, String, AttachmentOption...) for information about this parameter.
        options - Possible options to apply to this attachment, such as marking it as spoiler image
        Returns:
        WebhookMessageUpdateAction
        Throws:
        java.lang.IllegalArgumentException - If the provided data or filename is null.
      • deleteOriginal

        @Nonnull
        @CheckReturnValue
        default RestAction<java.lang.Void> deleteOriginal()
        Delete the original reply.
        This doesn't work for ephemeral messages.
        Returns:
        RestAction