Class AbstractWebhookClient<T>
- All Implemented Interfaces:
ISnowflake
,WebhookClient<T>
- Direct Known Subclasses:
IncomingWebhookClientImpl
,InteractionHookImpl
,WebhookImpl
-
Method Summary
Modifier and TypeMethodDescriptiondeleteMessageById
(String messageId) Delete a message from this webhook.editMessageAttachmentsById
(String messageId, Collection<? extends AttachedFile> attachments) Edit an existing message sent by this webhook.editMessageById
(String messageId, String content) Edit an existing message sent by this webhook.editMessageById
(String messageId, MessageEditData message) Edit an existing message sent by this webhook.editMessageComponentsById
(String messageId, Collection<? extends MessageTopLevelComponent> components) Edit an existing message sent by this webhook.editMessageEmbedsById
(String messageId, Collection<? extends MessageEmbed> embeds) Edit an existing message sent by this webhook.abstract WebhookMessageEditActionImpl
<T> editRequest
(String messageId) long
The Snowflake id of this entity.getJDA()
The associatedJDA
instance.getToken()
The token of this webhook.sendFiles
(Collection<? extends FileUpload> files) Send a message to this webhook.sendMessage
(String content) Send a message to this webhook.sendMessage
(MessageCreateData message) Send a message to this webhook.sendMessageComponents
(Collection<? extends MessageTopLevelComponent> components) Send a message to this webhook.sendMessageEmbeds
(Collection<? extends MessageEmbed> embeds) Send a message to this webhook.Send a message poll to this webhook.abstract WebhookMessageCreateActionImpl
<T> Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getTimeCreated
Methods inherited from interface net.dv8tion.jda.api.entities.WebhookClient
deleteMessageById, editMessageAttachmentsById, editMessageAttachmentsById, editMessageAttachmentsById, editMessageById, editMessageById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageComponentsById, editMessageEmbedsById, editMessageEmbedsById, editMessageEmbedsById, editMessageFormatById, editMessageFormatById, retrieveMessageById, sendFiles, sendMessageComponents, sendMessageComponents, sendMessageEmbeds, sendMessageFormat
-
Method Details
-
getIdLong
public long getIdLong()Description copied from interface:ISnowflake
The Snowflake id of this entity. This is unique to every entity and will never change.- Specified by:
getIdLong
in interfaceISnowflake
- Returns:
- Long containing the Id.
-
getToken
Description copied from interface:WebhookClient
The token of this webhook.- Specified by:
getToken
in interfaceWebhookClient<T>
- Returns:
- The token, or null if this webhook does not have a token available
-
getJDA
Description copied from interface:WebhookClient
The associatedJDA
instance.- Specified by:
getJDA
in interfaceWebhookClient<T>
- Returns:
- The JDA instance
-
sendRequest
-
editRequest
-
sendMessage
Description copied from interface:WebhookClient
Send a message to this webhook.If this is an
InteractionHook
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.MAX_FOLLOW_UP_MESSAGES_HIT
If this is anInteractionHook
and you sent more than 5 follow ups in a guild the bot isn't in.MESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Specified by:
sendMessage
in interfaceWebhookClient<T>
- Parameters:
content
- The message content- Returns:
WebhookMessageCreateAction
-
sendMessageEmbeds
@Nonnull public WebhookMessageCreateAction<T> sendMessageEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Description copied from interface:WebhookClient
Send a message to this webhook.If this is an
InteractionHook
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.MAX_FOLLOW_UP_MESSAGES_HIT
If this is anInteractionHook
and you sent more than 5 follow ups in a guild the bot isn't in.MESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
Example: Attachment Images
// Make a file upload instance which refers to a local file called "myFile.png" // The second parameter "image.png" is the filename we tell discord to use for the attachment FileUpload file = FileUpload.fromData(new File("myFile.png"), "image.png"); // Build a message embed which refers to this attachment by the given name. // Note that this must be the same name as configured for the attachment, not your local filename. MessageEmbed embed = new EmbedBuilder() .setDescription("This is my cute cat :)") .setImage("attachment://image.png") // refer to the file by using the "attachment://" schema with the filename we gave it above .build(); webhook.sendMessageEmbeds(Collections.singleton(embed)) // send the embeds .addFiles(file) // add the file as attachment .queue();
- Specified by:
sendMessageEmbeds
in interfaceWebhookClient<T>
- Parameters:
embeds
-MessageEmbeds
to use (up to 10)- Returns:
WebhookMessageCreateAction
-
sendMessageComponents
@Nonnull public WebhookMessageCreateAction<T> sendMessageComponents(@Nonnull Collection<? extends MessageTopLevelComponent> components) Description copied from interface:WebhookClient
Send a message to this webhook.If this is an
InteractionHook
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.MAX_FOLLOW_UP_MESSAGES_HIT
If this is anInteractionHook
and you sent more than 5 follow ups in a guild the bot isn't in.MESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Specified by:
sendMessageComponents
in interfaceWebhookClient<T>
- Parameters:
components
- TheMessageTopLevelComponents
to send, can contain up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).- Returns:
WebhookMessageCreateAction
-
sendMessage
Description copied from interface:WebhookClient
Send a message to this webhook.If this is an
InteractionHook
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.MAX_FOLLOW_UP_MESSAGES_HIT
If this is anInteractionHook
and you sent more than 5 follow ups in an interaction using onlyIntegrationType.USER_INSTALL
.MESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Specified by:
sendMessage
in interfaceWebhookClient<T>
- Parameters:
message
- TheMessageCreateData
to send- Returns:
WebhookMessageCreateAction
- See Also:
-
sendMessagePoll
Description copied from interface:WebhookClient
Send a message poll to this webhook.If this is an
InteractionHook
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.MAX_FOLLOW_UP_MESSAGES_HIT
If this is anInteractionHook
and you sent more than 5 follow ups in a guild the bot isn't in.MESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filterPOLL_INVALID_CHANNEL_TYPE
This channel does not allow pollsPOLL_WITH_UNUSABLE_EMOJI
This poll uses an external emoji that the bot is not allowed to use
- Specified by:
sendMessagePoll
in interfaceWebhookClient<T>
- Parameters:
poll
- TheMessagePollData
to send- Returns:
WebhookMessageCreateAction
- See Also:
-
sendFiles
@Nonnull public WebhookMessageCreateAction<T> sendFiles(@Nonnull Collection<? extends FileUpload> files) Description copied from interface:WebhookClient
Send a message to this webhook.If this is an
InteractionHook
this method will be delayed until the interaction is acknowledged.Resource Handling Note: Once the request is handed off to the requester, for example when you call
RestAction.queue()
, the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after usingFileUpload.fromData(File)
, before callingRestAction.queue()
. You can safely use a try-with-resources to handle this, sinceFileUpload.close()
becomes ineffective once the request is handed off.Example: Attachment Images
// Make a file upload instance which refers to a local file called "myFile.png" // The second parameter "image.png" is the filename we tell discord to use for the attachment FileUpload file = FileUpload.fromData(new File("myFile.png"), "image.png"); // Build a message embed which refers to this attachment by the given name. // Note that this must be the same name as configured for the attachment, not your local filename. MessageEmbed embed = new EmbedBuilder() .setDescription("This is my cute cat :)") .setImage("attachment://image.png") // refer to the file by using the "attachment://" schema with the filename we gave it above .build(); webhook.sendFiles(Collections.singleton(file)) // send the file upload .addEmbeds(embed) // add the embed you want to reference the file with .queue();
Possible
ErrorResponses
include:UNKNOWN_WEBHOOK
The webhook is no longer available, either it was deleted or in case of interactions it expired.MAX_FOLLOW_UP_MESSAGES_HIT
If this is anInteractionHook
and you sent more than 5 follow ups in a guild the bot isn't in.MESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRule
MESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filterREQUEST_ENTITY_TOO_LARGE
If the total sum of uploaded bytes exceeds the guild'supload limit
- Specified by:
sendFiles
in interfaceWebhookClient<T>
- Parameters:
files
- TheFileUploads
to attach to the message- Returns:
WebhookMessageCreateAction
- See Also:
-
editMessageById
@Nonnull public WebhookMessageEditActionImpl<T> editMessageById(@Nonnull String messageId, @Nonnull String content) Description copied from interface:WebhookClient
Edit an existing message sent by this webhook.If this is an
InteractionHook
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 existINVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageById
in interfaceWebhookClient<T>
- Parameters:
messageId
- The message id. For interactions this supports"@original"
to edit the source message of the interaction.content
- The new message content to use- Returns:
WebhookMessageEditAction
-
editMessageComponentsById
@Nonnull public WebhookMessageEditAction<T> editMessageComponentsById(@Nonnull String messageId, @Nonnull Collection<? extends MessageTopLevelComponent> components) Description copied from interface:WebhookClient
Edit an existing message sent by this webhook.If this is an
InteractionHook
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 existINVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageComponentsById
in interfaceWebhookClient<T>
- Parameters:
messageId
- The message id. For interactions this supports"@original"
to edit the source message of the interaction.components
- TheMessageTopLevelComponents
to set, can be empty to remove components, can contain up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).- Returns:
WebhookMessageEditAction
-
editMessageEmbedsById
@Nonnull public WebhookMessageEditActionImpl<T> editMessageEmbedsById(@Nonnull String messageId, @Nonnull Collection<? extends MessageEmbed> embeds) Description copied from interface:WebhookClient
Edit an existing message sent by this webhook.If this is an
InteractionHook
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 existINVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageEmbedsById
in interfaceWebhookClient<T>
- Parameters:
messageId
- The message id. For interactions this supports"@original"
to edit the source message of the interaction.embeds
-MessageEmbeds
to use (up to 10 in total)- Returns:
WebhookMessageEditAction
-
editMessageById
@Nonnull public WebhookMessageEditActionImpl<T> editMessageById(@Nonnull String messageId, @Nonnull MessageEditData message) Description copied from interface:WebhookClient
Edit an existing message sent by this webhook.If this is an
InteractionHook
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 existINVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageById
in interfaceWebhookClient<T>
- Parameters:
messageId
- The message id. For interactions this supports"@original"
to edit the source message of the interaction.message
- TheMessageEditData
containing the update information- Returns:
WebhookMessageEditAction
- See Also:
-
editMessageAttachmentsById
@Nonnull public WebhookMessageEditActionImpl<T> editMessageAttachmentsById(@Nonnull String messageId, @Nonnull Collection<? extends AttachedFile> attachments) Description copied from interface:WebhookClient
Edit an existing message sent by this webhook.If this is an
InteractionHook
this method will be delayed until the interaction is acknowledged.Resource Handling Note: Once the request is handed off to the requester, for example when you call
RestAction.queue()
, the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after usingFileUpload.fromData(File)
, before callingRestAction.queue()
. You can safely use a try-with-resources to handle this, sinceFileUpload.close()
becomes ineffective once the request is handed off.- Specified by:
editMessageAttachmentsById
in interfaceWebhookClient<T>
- Parameters:
messageId
- The message id. For interactions this supports"@original"
to edit the source message of the interaction.attachments
- The new attachments of the message (Can beFileUploads
orAttachmentUpdates
)- Returns:
MessageEditCallbackAction
that can be used to further update the message- See Also:
-
deleteMessageById
Description copied from interface:WebhookClient
Delete a message from this webhook.Use
setThreadId(threadId)
to delete messages from threads.If this is an
InteractionHook
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
- Specified by:
deleteMessageById
in interfaceWebhookClient<T>
- Parameters:
messageId
- The id for the message to delete- Returns:
WebhookMessageDeleteAction
-