Class WebhookClient

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class WebhookClient
    extends java.lang.Object
    implements java.lang.AutoCloseable
    WebhookClient representing an executable Webhook
    This client allows to send messages to a Discord Webhook without reliance on a JDA instance/Webhook entity.

    Instances of this class can be retrieved using WebhookClientBuilders

    • Field Detail

      • USER_AGENT

        public static final java.lang.String USER_AGENT
      • LOG

        public static final org.slf4j.Logger LOG
    • Method Detail

      • getIdLong

        public long getIdLong()
        The snowflake id of the target Webhook
        Returns:
        id of the target Webhook
      • getId

        public java.lang.String getId()
        The snowflake id of the target Webhook
        Returns:
        id of the target Webhook
      • getUrl

        public java.lang.String getUrl()
        The URL of this WebhookClient
        Returns:
        The URL of this client
      • send

        public RequestFuture<?> send​(java.io.File file)
        Sends the provided File to this webhook.
        Use WebhookMessage.files(String, Object, Object...) to send up to 10 files!
        Parameters:
        file - The file to send
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If the provided file is null, does not exist or is not readable
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • send

        public RequestFuture<?> send​(java.io.File file,
                                     java.lang.String fileName)
        Sends the provided File to this webhook.
        Use WebhookMessage.files(String, Object, Object...) to send up to 10 files!
        Parameters:
        file - The file to send
        fileName - The name that should be used for this file
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If the provided file is null, does not exist or is not readable
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • send

        public RequestFuture<?> send​(byte[] data,
                                     java.lang.String fileName)
        Sends the provided byte[] data to this webhook.
        Use WebhookMessage.files(String, Object, Object...) to send up to 10 files!
        Parameters:
        data - The file data to send
        fileName - The name that should be used for this file
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If the provided data is null or exceeds the limit of 8MB
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • send

        public RequestFuture<?> send​(java.io.InputStream data,
                                     java.lang.String fileName)
        Sends the provided InputStream data to this webhook.
        Use WebhookMessage.files(String, Object, Object...) to send up to 10 files!
        Parameters:
        data - The file data to send
        fileName - The name that should be used for this file
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If the provided data is null
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • send

        public RequestFuture<?> send​(Message message)
        Sends the provided Message to this webhook.

        Hint: Use MessageBuilder to create a Message instance!

        Parameters:
        message - The message to send
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If the provided message is null
      • send

        public RequestFuture<?> send​(MessageEmbed[] embeds)
        Sends the provided MessageEmbeds to this webhook.

        You can send up to 10 embeds per message! If more are sent they will not be displayed.

        Hint: Use EmbedBuilder to create a MessageEmbed instance!

        Parameters:
        embeds - The embeds to send
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If any of the provided embeds is null
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • send

        public RequestFuture<?> send​(MessageEmbed first,
                                     MessageEmbed... embeds)
        Sends the provided MessageEmbeds to this webhook.

        You can send up to 10 embeds per message! If more are sent they will not be displayed.

        Hint: Use EmbedBuilder to create a MessageEmbed instance!

        Parameters:
        first - The first embed
        embeds - The other embeds to send
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If any of the provided embeds is null
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • send

        public RequestFuture<?> send​(java.util.Collection<MessageEmbed> embeds)
        Sends the provided MessageEmbeds to this webhook.

        You can send up to 10 embeds per message! If more are sent they will not be displayed.

        Hint: Use EmbedBuilder to create a MessageEmbed instance!

        Parameters:
        embeds - The embeds to send
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If any of the provided embeds is null
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • send

        public RequestFuture<?> send​(java.lang.String content)
        Sends the provided text message to this webhook.
        Parameters:
        content - The text message to send
        Returns:
        RequestFuture representing the execution task, this will be completed once the message was sent.
        Throws:
        java.lang.IllegalArgumentException - If any of the provided message is null, blank or exceeds 2000 characters in length
        java.util.concurrent.RejectedExecutionException - If this client was closed
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable