Interface InteractionHook
-
- All Superinterfaces:
WebhookClient<Message>
public interface InteractionHook extends WebhookClient<Message>
Webhook API for an interaction. Valid for up to 15 minutes after the interaction.
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:
Interaction.deferReply(...)
Interaction.reply(...)
ComponentInteraction.deferEdit()
-
ComponentInteraction.editMessage(...)
When
Interaction.deferReply()
is used, the first message will act identically toeditOriginal(...)
. 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 indeferReply(boolean)
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default RestAction<java.lang.Void>
deleteOriginal()
Delete the original reply.default WebhookMessageUpdateAction<Message>
editOriginal(byte[] data, java.lang.String name, AttachmentOption... options)
Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal(java.io.File file, java.lang.String name, AttachmentOption... options)
Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal(java.io.File file, AttachmentOption... options)
Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal(java.io.InputStream data, java.lang.String name, AttachmentOption... options)
Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginal(java.lang.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(java.util.Collection<? extends ComponentLayout> components)
Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginalComponents(ComponentLayout... components)
Edit the source message sent by this interaction.default WebhookMessageUpdateAction<Message>
editOriginalEmbeds(java.util.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(java.lang.String format, java.lang.Object... args)
Edit the source message sent by this interaction.default long
getExpirationTimestamp()
The unix millisecond timestamp for the expiration of this interaction hook.Interaction
getInteraction()
The interaction attached to this hook.JDA
getJDA()
The JDA instance for this interactiondefault boolean
isExpired()
Whether this interaction has expired.RestAction<Message>
retrieveOriginal()
Retrieves the original reply to this interaction.InteractionHook
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 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 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
@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.lang.String content)
Edit the source message sent by this interaction.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided content is null, empty, or longer thanMessage.MAX_CONTENT_LENGTH
-
editOriginalComponents
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalComponents(@Nonnull java.util.Collection<? extends ComponentLayout> components)
Edit the source message sent by this interaction.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided components are null, or more than 5 layouts are provided
-
editOriginalComponents
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalComponents(@Nonnull ComponentLayout... components)
Edit the source message sent by this interaction.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided components are null, or more than 5 layouts are provided
-
editOriginalEmbeds
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalEmbeds(@Nonnull java.util.Collection<? extends MessageEmbed> embeds)
Edit the source message sent by this interaction.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.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.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.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.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided message is null
-
editOriginalFormat
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginalFormat(@Nonnull java.lang.String format, @Nonnull java.lang.Object... args)
Edit the source message sent by this interaction.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the formatted string is null, empty, or longer thanMessage.MAX_CONTENT_LENGTH
-
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.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided data, or filename isnull
.
-
editOriginal
@Nonnull @CheckReturnValue default WebhookMessageUpdateAction<Message> editOriginal(@Nonnull java.io.File file, @Nonnull AttachmentOption... options)
Edit the source message sent by this interaction.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided file isnull
.
-
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.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided file or filename isnull
.
-
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.
ForComponentInteraction.editComponents(Collection)
andComponentInteraction.deferEdit()
this will be the message the components are attached to. ForInteraction.deferReply()
andInteraction.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:
java.lang.IllegalArgumentException
- If the provided data or filename isnull
.
-
deleteOriginal
@Nonnull @CheckReturnValue default RestAction<java.lang.Void> deleteOriginal()
Delete the original reply.
This doesn't work for ephemeral messages.- Returns:
RestAction
-
-