Interface InteractionHook
- All Superinterfaces:
ISnowflake
,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 WebhookMessageEditAction<Message>
editOriginal
(String content) Edit the source message sent by this interaction.default WebhookMessageEditAction<Message>
editOriginal
(MessageEditData message) Edit the source message sent by this interaction.default WebhookMessageEditAction<Message>
editOriginalAttachments
(Collection<? extends AttachedFile> attachments) default WebhookMessageEditAction<Message>
editOriginalAttachments
(AttachedFile... attachments) default WebhookMessageEditAction<Message>
editOriginalComponents
(Collection<? extends LayoutComponent> components) Edit the source message sent by this interaction.default WebhookMessageEditAction<Message>
editOriginalComponents
(LayoutComponent... components) Edit the source message sent by this interaction.default WebhookMessageEditAction<Message>
editOriginalEmbeds
(Collection<? extends MessageEmbed> embeds) Edit the source message sent by this interaction.default WebhookMessageEditAction<Message>
editOriginalEmbeds
(MessageEmbed... embeds) Edit the source message sent by this interaction.default WebhookMessageEditAction<Message>
editOriginalFormat
(String format, Object... args) Edit the source message sent by this interaction.static InteractionHook
Creates an instance ofInteractionHook
capable of executing webhook requests.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.default RestAction<Message>
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.ISnowflake
getId, getIdLong, getTimeCreated
Methods inherited from interface net.dv8tion.jda.api.entities.WebhookClient
deleteMessageById, deleteMessageById, editMessageAttachmentsById, editMessageAttachmentsById, editMessageAttachmentsById, editMessageAttachmentsById, editMessageById, editMessageById, editMessageById, editMessageById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageEmbedsById, editMessageEmbedsById, editMessageEmbedsById, editMessageEmbedsById, editMessageFormatById, editMessageFormatById, getToken, retrieveMessageById, sendFiles, sendFiles, sendMessage, sendMessage, sendMessageComponents, sendMessageComponents, sendMessageEmbeds, sendMessageEmbeds, sendMessageFormat, sendMessagePoll
-
Method Details
-
getInteraction
The interaction attached to this hook.- Returns:
- The
Interaction
- Throws:
IllegalStateException
- If this instance was created throughfrom(JDA, String)
-
getExpirationTimestamp
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 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- Specified by:
getJDA
in interfaceWebhookClient<Message>
- 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 WebhookMessageEditAction<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:
WebhookMessageEditAction
- Throws:
IllegalArgumentException
- If the provided content is null, empty, or longer thanMessage.MAX_CONTENT_LENGTH
-
editOriginalComponents
@Nonnull @CheckReturnValue default WebhookMessageEditAction<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:
WebhookMessageEditAction
- Throws:
IllegalArgumentException
- If the provided components are null, or more than 5 layouts are provided
-
editOriginalComponents
@Nonnull @CheckReturnValue default WebhookMessageEditAction<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:
WebhookMessageEditAction
- Throws:
IllegalArgumentException
- If the provided components are null, or more than 5 layouts are provided
-
editOriginalEmbeds
@Nonnull @CheckReturnValue default WebhookMessageEditAction<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:
WebhookMessageEditAction
- Throws:
IllegalArgumentException
- If the provided embeds are null, or more than 10
-
editOriginalEmbeds
@Nonnull @CheckReturnValue default WebhookMessageEditAction<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:
WebhookMessageEditAction
- Throws:
IllegalArgumentException
- If the provided embeds are null, or more than 10
-
editOriginal
@Nonnull @CheckReturnValue default WebhookMessageEditAction<Message> editOriginal(@Nonnull MessageEditData 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:
WebhookMessageEditAction
- Throws:
IllegalArgumentException
- If the provided message is null
-
editOriginalFormat
@Nonnull @CheckReturnValue default WebhookMessageEditAction<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:
WebhookMessageEditAction
- Throws:
IllegalArgumentException
- If the formatted string is null, empty, or longer thanMessage.MAX_CONTENT_LENGTH
-
editOriginalAttachments
@Nonnull @CheckReturnValue default WebhookMessageEditAction<Message> editOriginalAttachments(@Nonnull Collection<? extends AttachedFile> attachments) -
editOriginalAttachments
@Nonnull @CheckReturnValue default WebhookMessageEditAction<Message> editOriginalAttachments(@Nonnull AttachedFile... attachments) -
deleteOriginal
Delete the original reply.- Returns:
RestAction
-
from
Creates an instance ofInteractionHook
capable of executing webhook requests.Messages created by this client may not have a fully accessible channel or guild available, and
getInteraction()
throws. The messages might report a channel of typeUNKNOWN
, in which case the channel is assumed to be inaccessible and limited to only webhook requests.- Parameters:
jda
- The JDA instance, used to handle rate-limitstoken
- The interaction token for the webhook- Returns:
- The
InteractionHook
instance - Throws:
IllegalArgumentException
- If null is provided or the token is blank
-