Interface InteractionHook
- All Superinterfaces:
WebhookClient<Message>
This can be used to send followup messages or edit the original message of an interaction.
The interaction has to be acknowledged before any of these actions can be performed. First, you need to call one of:
When IReplyCallback.deferReply()
is used, the first message will act identically to editOriginal(...)
.
This means that you cannot make your deferred reply ephemeral through this interaction hook.
You need to specify whether your reply is ephemeral or not directly in deferReply(boolean)
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault RestAction<Void>
Delete the original reply.default WebhookMessageUpdateAction<Message>
editOriginal
(byte[] data, String name, AttachmentOption... options) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal
(File file, String name, AttachmentOption... options) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal
(File file, AttachmentOption... options) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal
(InputStream data, String name, AttachmentOption... options) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal
(String content) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal
(Message message) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginalComponents
(Collection<? extends LayoutComponent> components) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginalComponents
(LayoutComponent... components) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginalEmbeds
(Collection<? extends MessageEmbed> embeds) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginalEmbeds
(MessageEmbed... embeds) Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginalFormat
(String format, Object... args) Edit the source message sent by this interaction.default long
The unix millisecond timestamp for the expiration of this interaction hook.The interaction attached to this hook.getJDA()
The JDA instance for this interactiondefault boolean
Whether this interaction has expired.Retrieves the original reply to this interaction.setEphemeral
(boolean ephemeral) Whether messages sent from this interaction hook should be ephemeral by default.Methods inherited from interface net.dv8tion.jda.api.entities.WebhookClient
deleteMessageById, deleteMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageEmbedsById, editMessageEmbedsById, editMessageEmbedsById, editMessageEmbedsById, editMessageFormatById, editMessageFormatById, sendFile, sendFile, sendFile, sendFile, sendMessage, sendMessage, sendMessageEmbeds, sendMessageEmbeds, sendMessageFormat
-
Method Details
-
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:
-
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:
-
setEphemeral
Whether messages sent from this interaction hook should be ephemeral by default.
This does not affect message updates, including deferred replies sent withsendMessage(...)
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
The JDA instance for this interaction- Returns:
- The JDA instance
-
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 String content) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.reply(String)
this will be the reply message instead.This method will be delayed until the interaction is acknowledged.
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:
content
- The new message content to use- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the provided content is null, empty, or longer thanMessage.MAX_CONTENT_LENGTH
-
editOriginalComponents
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalComponents(@Nonnull Collection<? extends LayoutComponent> components) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.reply(String)
this will be the reply message instead.This method will be delayed until the interaction is acknowledged.
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:
components
- The new component layouts for this message, such asActionRows
- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the provided components are null, or more than 5 layouts are provided
-
editOriginalComponents
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalComponents(@Nonnull LayoutComponent... components) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.reply(String)
this will be the reply message instead.This method will be delayed until the interaction is acknowledged.
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:
components
- The new component layouts for this message, such asActionRows
- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the provided components are null, or more than 5 layouts are provided
-
editOriginalEmbeds
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.reply(String)
this will be the reply message instead.This method will be delayed until the interaction is acknowledged.
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:
embeds
-MessageEmbeds
to use (up to 10 in total)- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the provided embeds are null, or more than 10
-
editOriginalEmbeds
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalEmbeds(@Nonnull MessageEmbed... embeds) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.reply(String)
this will be the reply message instead.This method will be delayed until the interaction is acknowledged.
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:
embeds
- The newMessageEmbeds
to use- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the provided embeds are null, or more than 10
-
editOriginal
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginal(@Nonnull Message message) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.reply(String)
this will be the reply message instead.This method will be delayed until the interaction is acknowledged.
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:
message
- The new message to replace the existing message with- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the provided message is null
-
editOriginalFormat
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalFormat(@Nonnull String format, @Nonnull Object... args) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.reply(String)
this will be the reply message instead.This method will be delayed until the interaction is acknowledged.
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:
format
- Format string for the message contentargs
- Format arguments for the content- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the formatted string is null, empty, or longer thanMessage.MAX_CONTENT_LENGTH
-
editOriginal
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginal(@Nonnull InputStream data, @Nonnull String name, @Nonnull AttachmentOption... options) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.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 URIattachment://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 forWebhookClient.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:
IllegalArgumentException
- If the provided data, or filename isnull
.
-
editOriginal
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginal(@Nonnull File file, @Nonnull AttachmentOption... options) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.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 usingFile.getName()
.editOriginal(file, file.getName())
Uploading images with Embeds
When uploading an image you can reference said image using the specified filename as URIattachment://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
- TheFile
data to upload to the webhook.options
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
WebhookMessageUpdateAction
- Throws:
IllegalArgumentException
- If the provided file isnull
.
-
editOriginal
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginal(@Nonnull File file, @Nonnull String name, @Nonnull AttachmentOption... options) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.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 URIattachment://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
- TheFile
data to upload to the webhook.name
- The file name that should be sent to discord
Refer to the documentation forWebhookClient.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:
IllegalArgumentException
- If the provided file or filename isnull
.
-
editOriginal
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginal(@Nonnull byte[] data, @Nonnull String name, @Nonnull AttachmentOption... options) Edit the source message sent by this interaction.
ForIMessageEditCallback.editComponents(Collection)
andIMessageEditCallback.deferEdit()
this will be the message the components are attached to. ForIReplyCallback.deferReply()
andIReplyCallback.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 URIattachment://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 forWebhookClient.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:
IllegalArgumentException
- If the provided data or filename isnull
.
-
deleteOriginal
Delete the original reply.
This doesn't work for ephemeral messages.- Returns:
RestAction
-