Interface Webhook

All Superinterfaces:
ISnowflake, WebhookClient<Message>

public interface Webhook extends ISnowflake, WebhookClient<Message>
An object representing Webhooks in Discord
See Also:
  • Field Details

    • WEBHOOK_URL

      static final Pattern WEBHOOK_URL
      Pattern for a Webhook URL.

      Groups

      Javadoc is stupid, this is not a required tag
      Index Name Description
      0 N/A The entire link
      1 id The ID of the webhook
      2 token The token of the webhook
      You can use the names with Matcher.group(String) and the index with Matcher.group(int).
  • Method Details

    • getJDA

      @Nonnull JDA getJDA()
      The JDA instance of this Webhook.
      Specified by:
      getJDA in interface WebhookClient<Message>
      Returns:
      The current JDA instance of this Webhook
    • getType

      @Nonnull WebhookType getType()
      The WebhookType of this webhook.
      Webhooks of type WebhookType.FOLLOWER don't have a token.
      Returns:
      The WebhookType
    • isPartial

      boolean isPartial()
      Whether this webhook cannot provide getChannel() and getGuild().
      This means that the webhook is not local to this shard's cache and cannot provide full channel/guild references.
      Returns:
      True, if getChannel() and getGuild() would throw
    • getGuild

      @Nonnull Guild getGuild()
      The Guild instance for this Webhook.
      This is a shortcut for getChannel().getGuild().
      Returns:
      The current Guild of this Webhook
      Throws:
      IllegalStateException - If this webhooks is partial
    • getChannel

      @Nonnull IWebhookContainerUnion getChannel()
      The channel instance this Webhook is attached to. Webhooks are created on specific channels so that they can interact with that channel. With regard to threads, Webhooks are attached to their parent channel and then the Webhooks can post to the parent and the thread too.
      Returns:
      The current channel that this webhook is attached to.
      Throws:
      IllegalStateException - If this webhooks is partial
    • getOwner

      @Nullable Member getOwner()
      The owner of this Webhook. This will be null for some Webhooks, such as those retrieved from Audit Logs.
      This requires the member to be cached. You can use getOwnerAsUser() to get a reference to the user instead.
      Returns:
      Possibly-null Member instance representing the owner of this Webhook.
    • getOwnerAsUser

      @Nullable User getOwnerAsUser()
      The owner of this Webhook. This will be null for some Webhooks, such as those retrieved from Audit Logs.
      This can be non-null even when getOwner() is null. getOwner() requires the webhook to be local to this shard and in cache.
      Returns:
      Possibly-null User instance representing the owner of this Webhook.
    • getDefaultUser

      @Nonnull User getDefaultUser()
      The default User for this Webhook.

      The User returned is always fake and cannot be interacted with.
      This User is used for all messages posted to the Webhook route (found in getUrl()), it holds the default references for the message authors of messages by this Webhook.

      When POSTing to a Webhook route the name/avatar of this default user can be overridden.

      Returns:
      A fake User instance representing the default webhook user.
      See Also:
    • getName

      @Nonnull String getName()
      The name of this Webhook.
      This will be displayed by default as the author name of every message by this Webhook.

      This is a shortcut for getDefaultUser().getName().

      Returns:
      The name of this Webhook
    • getToken

      @Nullable String getToken()
      The execute token for this Webhook.
      This can be used to modify/delete/execute this Webhook.

      Note: Some Webhooks, such as those retrieved from Audit Logs, do not contain a token

      Specified by:
      getToken in interface WebhookClient<Message>
      Returns:
      The execute token for this Webhook
    • getUrl

      @Nonnull String getUrl()
      The POST route for this Webhook.
      This contains the token and id of this Webhook. Some Webhooks without tokens (such as those retrieved from Audit Logs) will return a URL without a token.

      The route returned by this method does not need permission checks to be executed.
      It is implied that Webhook messages always have all permissions including mentioning everyone.

      Webhook executions are limited with 5 requests per second. The response contains rate limit headers that should be handled by execution frameworks. (Learn More)

      Returns:
      The execution route for this Webhook.
    • getSourceChannel

      @Nullable Webhook.ChannelReference getSourceChannel()
      The source channel for a Webhook of type FOLLOWER.
      Returns:
      Webhook.ChannelReference
    • getSourceGuild

      @Nullable Webhook.GuildReference getSourceGuild()
      The source guild for a Webhook of type FOLLOWER.
      Returns:
      Webhook.GuildReference
    • delete

      @Nonnull @CheckReturnValue AuditableRestAction<Void> delete()
      Deletes this Webhook.

      The following ErrorResponses are possible:

      Returns:
      AuditableRestAction
      The rest action to delete this Webhook.
      Throws:
      InsufficientPermissionException - If the Webhook does not have a token, such as the Webhooks retrieved from Audit Logs and the currently logged in account does not have Permission.MANAGE_WEBHOOKS in this channel.
    • delete

      @Nonnull @CheckReturnValue AuditableRestAction<Void> delete(@Nonnull String token)
      Deletes this Webhook.

      The following ErrorResponses are possible:

      Parameters:
      token - The webhook token (this is not the bot authorization token!)
      Returns:
      AuditableRestAction
      The rest action to delete this Webhook.
      Throws:
      IllegalArgumentException - If the provided token is null
    • getManager

      @Nonnull @CheckReturnValue WebhookManager getManager()
      The WebhookManager for this Webhook.
      You can modify multiple fields in one request by chaining setters before calling RestAction.queue().
      Returns:
      The WebhookManager for this Webhook
      Throws:
      InsufficientPermissionException - If the currently logged in account does not have Permission.MANAGE_WEBHOOKS