Interface IReplyCallback
- All Superinterfaces:
IDeferrableCallback
,Interaction
,ISnowflake
- All Known Subinterfaces:
ButtonInteraction
,CommandInteraction
,ComponentInteraction
,ContextInteraction<T>
,MessageContextInteraction
,SelectMenuInteraction
,SlashCommandInteraction
,UserContextInteraction
- All Known Implementing Classes:
ButtonInteractionEvent
,GenericCommandInteractionEvent
,GenericComponentInteractionCreateEvent
,GenericContextInteractionEvent
,MessageContextInteractionEvent
,SelectMenuInteractionEvent
,SlashCommandInteractionEvent
,UserContextInteractionEvent
These replies automatically acknowledge the interaction and support deferring.
Deferred Replies
If an interaction reply is deferred usingdeferReply()
or deferReply(boolean)
,
the interaction hook
can be used to send a delayed/deferred reply with WebhookClient.sendMessage(String)
.
When using deferReply()
the first message sent to the InteractionHook
will be identical to using InteractionHook.editOriginal(String)
.
You must decide whether your reply will be ephemeral or not before calling deferReply()
. So design your code flow with that in mind!
If a reply is deferred
, it becomes the original message of the interaction hook.
This means all the methods with original
in the name, such as InteractionHook.editOriginal(String)
,
will affect that original reply.
-
Method Summary
Modifier and TypeMethodDescriptionAcknowledge this interaction and defer the reply to a later time.default ReplyCallbackAction
deferReply
(boolean ephemeral) Acknowledge this interaction and defer the reply to a later time.default ReplyCallbackAction
Reply to this interaction and acknowledge it.default ReplyCallbackAction
Reply to this interaction and acknowledge it.default ReplyCallbackAction
replyEmbeds
(Collection<? extends MessageEmbed> embeds) Reply to this interaction and acknowledge it.default ReplyCallbackAction
replyEmbeds
(MessageEmbed embed, MessageEmbed... embeds) Reply to this interaction and acknowledge it.default ReplyCallbackAction
replyFile
(byte[] data, String name, AttachmentOption... options) Reply to this interaction and acknowledge it.default ReplyCallbackAction
replyFile
(File file, String name, AttachmentOption... options) Reply to this interaction and acknowledge it.default ReplyCallbackAction
replyFile
(File file, AttachmentOption... options) Reply to this interaction and acknowledge it.default ReplyCallbackAction
replyFile
(InputStream data, String name, AttachmentOption... options) Reply to this interaction and acknowledge it.default ReplyCallbackAction
replyFormat
(String format, Object... args) Reply to this interaction and acknowledge it.Methods inherited from interface net.dv8tion.jda.api.interactions.callbacks.IDeferrableCallback
getHook
Methods inherited from interface net.dv8tion.jda.api.interactions.Interaction
getChannel, getChannelType, getGuild, getGuildChannel, getGuildLocale, getJDA, getMember, getMessageChannel, getNewsChannel, getPrivateChannel, getTextChannel, getThreadChannel, getToken, getType, getTypeRaw, getUser, getUserLocale, getVoiceChannel, isAcknowledged, isFromGuild
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
Method Details
-
deferReply
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 eitherInteractionHook.editOriginal(String)
orWebhookClient.sendMessage(String)
.You can use
deferReply(true)
to send a deferred ephemeral reply. If your initial deferred message is not ephemeral it cannot be made ephemeral later. Your first message to theInteractionHook
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 receiveErrorResponse.UNKNOWN_INTERACTION
.Use
reply(String)
to reply directly.- Returns:
ReplyCallbackAction
-
deferReply
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 eitherInteractionHook.editOriginal(String)
orWebhookClient.sendMessage(String)
.You can use
deferReply()
ordeferReply(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 theInteractionHook
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 receiveErrorResponse.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:
ReplyCallbackAction
-
reply
Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.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:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If null is provided
-
reply
Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.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:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If null is provided or the content is empty or longer thanMessage.MAX_CONTENT_LENGTH
-
replyEmbeds
@Nonnull @CheckReturnValue default ReplyCallbackAction replyEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.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
- TheMessageEmbeds
to send- Returns:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If null is provided
-
replyEmbeds
@Nonnull @CheckReturnValue default ReplyCallbackAction 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 usesetEphemeral(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 receiveErrorResponse.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 sendembeds
- Any additional embeds to send- Returns:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If null is provided
-
replyFormat
@Nonnull @CheckReturnValue default ReplyCallbackAction replyFormat(@Nonnull String format, @Nonnull Object... args) Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.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 contentargs
- Format arguments for the content- Returns:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If the format string is null or the resulting content is longer thanMessage.MAX_CONTENT_LENGTH
-
replyFile
@Nonnull @CheckReturnValue default ReplyCallbackAction replyFile(@Nonnull InputStream data, @Nonnull String name, @Nonnull AttachmentOption... options) Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.UNKNOWN_INTERACTION
.If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use
deferReply()
instead.Possible
ErrorResponses
include:REQUEST_ENTITY_TOO_LARGE
The file exceeds the maximum upload size ofMessage.MAX_FILE_SIZE
- Parameters:
data
- The InputStream data to uploadname
- The file name that should be sent to discord
Refer to the documentation forreplyFile(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:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If the provided file or filename isnull
orempty
.
-
replyFile
@Nonnull @CheckReturnValue default ReplyCallbackAction replyFile(@Nonnull File file, @Nonnull AttachmentOption... options) Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.UNKNOWN_INTERACTION
.If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use
deferReply()
instead.This is a shortcut to
replyFile(java.io.File, String, AttachmentOption...)
by way of usingFile.getName()
.sendFile(file, file.getName())
Possible
ErrorResponses
include:REQUEST_ENTITY_TOO_LARGE
The file exceeds the maximum upload size ofMessage.MAX_FILE_SIZE
- Parameters:
file
- TheFile
data to uploadoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If the provided file isnull
.
-
replyFile
@Nonnull @CheckReturnValue default ReplyCallbackAction replyFile(@Nonnull File file, @Nonnull String name, @Nonnull AttachmentOption... options) Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.UNKNOWN_INTERACTION
.If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use
deferReply()
instead.The
name
parameter is used to inform Discord about what the file should be called. This is 2 fold:- The file name provided is the name that is found in
Message.Attachment.getFileName()
after upload and it is the name that will show up in the client when the upload is displayed.
Note: The fileName does not show up on the Desktop client for images. It does on mobile however. - The extension of the provided fileName also determines how Discord will treat the file. Discord currently only has special handling for image file types, but the fileName's extension must indicate that it is an image file. This means it has to end in something like .png, .jpg, .jpeg, .gif, etc. As a note, you can also not provide a full name for the file and instead ONLY provide the extension like "png" or "gif" and Discord will generate a name for the upload and append the fileName as the extension.
Possible
ErrorResponses
include:REQUEST_ENTITY_TOO_LARGE
The file exceeds the maximum upload size ofMessage.MAX_FILE_SIZE
- Parameters:
file
- TheFile
data to uploadname
- The file name that should be sent to discordoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If the provided file or filename isnull
orempty
.
- The file name provided is the name that is found in
-
replyFile
@Nonnull @CheckReturnValue default ReplyCallbackAction replyFile(@Nonnull byte[] data, @Nonnull String name, @Nonnull AttachmentOption... options) Reply to this interaction and acknowledge it.
This will send a reply message for this interaction. You can usesetEphemeral(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 receiveErrorResponse.UNKNOWN_INTERACTION
.If your handling can take longer than 3 seconds, due to various rate limits or other conditions, you should use
deferReply()
instead.Possible
ErrorResponses
include:REQUEST_ENTITY_TOO_LARGE
The file exceeds the maximum upload size ofMessage.MAX_FILE_SIZE
- Parameters:
data
- Thebyte[]
data to uploadname
- The file name that should be sent to discord
Refer to the documentation forreplyFile(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:
ReplyCallbackAction
- Throws:
IllegalArgumentException
- If the provided file or filename isnull
orempty
.
-