Class WebhookClientBuilder


  • public class WebhookClientBuilder
    extends java.lang.Object
    Builder that creates a new WebhookClient instance
    • Field Detail

      • DEFAULT_HTTP_BUILDER

        public static final okhttp3.OkHttpClient.Builder DEFAULT_HTTP_BUILDER
    • Constructor Detail

      • WebhookClientBuilder

        public WebhookClientBuilder​(long id,
                                    java.lang.String token)
        Creates a new WebhookClientBuilder with the provided id and token
        Parameters:
        id - The snowflake id of the target webhook
        token - The authorization token of the target webhook
        This is not a bot/client token!
        Throws:
        java.lang.IllegalArgumentException - If the provided token is null or contains any whitespace!
      • WebhookClientBuilder

        public WebhookClientBuilder​(@Nonnull
                                    java.lang.String url)
        Creates a new WebhookClientBuilder with the provided webhook URL
        Parameters:
        url - The URL of the webhook. May be directly copied from Discord's UI
        Example: https://discordapp.com/api/webhooks/123456789012345678/my-webhook-token
        This constructor also parses URLs pointing to subdomains of discordapp.com
        Throws:
        java.lang.IllegalArgumentException - If the provided URL is null or is incorrectly formatted
      • WebhookClientBuilder

        public WebhookClientBuilder​(@Nonnull
                                    Webhook webhook)
        Creates a new WebhookClientBuilder with the provided id and token
        Parameters:
        webhook - The target Webhook
        Throws:
        java.lang.NullPointerException - If the provided Webhook is null
    • Method Detail

      • setExecutorService

        public WebhookClientBuilder setExecutorService​(@Nullable
                                                       java.util.concurrent.ScheduledExecutorService executorService)
        The ScheduledExecutorService that should be used to handle rate limits!
        By default this creates a new executor with 1 core thread!

        Closing the WebhookClient will close this executor service!

        Parameters:
        executorService - The executor service that should be used
        Returns:
        The current WebhookClientBuilder for chaining convenience
      • setHttpClient

        public WebhookClientBuilder setHttpClient​(@Nullable
                                                  okhttp3.OkHttpClient client)
        The OkHttpClient that should be used to make HTTP requests!

        Setting this will skip the setHttpClientBuilder(OkHttpClient.Builder) setting and directly use the provided client!

        Parameters:
        client - The client that should be used
        Returns:
        The current WebhookClientBuilder for chaining convenience
      • setHttpClientBuilder

        public WebhookClientBuilder setHttpClientBuilder​(@Nullable
                                                         okhttp3.OkHttpClient.Builder builder)
        The OkHttpClient.Builder that should be used to create the OkHttpClient of the resulting WebhookClient!
        If not set or null this builder will use the DEFAULT_HTTP_BUILDER instance.

        This setting is ignored if setHttpClient(okhttp3.OkHttpClient) is set!

        Parameters:
        builder - The builder that should be used
        Returns:
        The current WebhookClientBuilder for chaining convenience
      • setThreadFactory

        public WebhookClientBuilder setThreadFactory​(@Nullable
                                                     java.util.concurrent.ThreadFactory factory)
        Factory that should be used by the default ScheduledExecutorService to create Threads for rate limitation handling of the created WebhookClient!
        This allows changing thread information such as name without having to create your own executor.
        Parameters:
        factory - The ThreadFactory that will be used when no ScheduledExecutorService has been set via setExecutorService(ScheduledExecutorService)
        Returns:
        The current WebhookClientBuilder for chaining convenience
      • setDaemon

        public WebhookClientBuilder setDaemon​(boolean isDaemon)
        Whether rate limit threads of the created WebhookClient should be treated as Thread.isDaemon() or not.
        Default: false

        This will not be used when the default thread pool has been set via setExecutorService(ScheduledExecutorService)!

        Parameters:
        isDaemon - True, if the threads should be daemon
        Returns:
        The current WebhookClientBuilder for chaining convenience
      • build

        public WebhookClient build()
        Builds a new WebhookClient instance with the current state of this builder.

        Remember to close the WebhookClient once you don't need it anymore to free resources!

        Returns:
        The new WebhookClient instance