Package net.dv8tion.jda.webhook
Class WebhookClientBuilder
- java.lang.Object
-
- net.dv8tion.jda.webhook.WebhookClientBuilder
-
public class WebhookClientBuilder extends java.lang.Object
Builder that creates a newWebhookClient
instance
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
WebhookClientBuilder.DefaultWebhookThreadFactory
-
Field Summary
Fields Modifier and Type Field Description static okhttp3.OkHttpClient.Builder
DEFAULT_HTTP_BUILDER
-
Constructor Summary
Constructors Constructor Description WebhookClientBuilder(long id, java.lang.String token)
Creates a new WebhookClientBuilder with the provided id and tokenWebhookClientBuilder(java.lang.String url)
Creates a new WebhookClientBuilder with the provided webhook URLWebhookClientBuilder(Webhook webhook)
Creates a new WebhookClientBuilder with the provided id and token
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebhookClient
build()
Builds a newWebhookClient
instance with the current state of this builder.WebhookClientBuilder
setDaemon(boolean isDaemon)
Whether rate limit threads of the createdWebhookClient
should be treated asThread.isDaemon()
or not.WebhookClientBuilder
setExecutorService(java.util.concurrent.ScheduledExecutorService executorService)
TheScheduledExecutorService
that should be used to handle rate limits!
By default this creates a new executor with 1 core thread!WebhookClientBuilder
setHttpClient(okhttp3.OkHttpClient client)
TheOkHttpClient
that should be used to make HTTP requests!WebhookClientBuilder
setHttpClientBuilder(okhttp3.OkHttpClient.Builder builder)
TheOkHttpClient.Builder
that should be used to create theOkHttpClient
of the resultingWebhookClient
!
If not set ornull
this builder will use theDEFAULT_HTTP_BUILDER
instance.WebhookClientBuilder
setThreadFactory(java.util.concurrent.ThreadFactory factory)
Factory that should be used by the defaultScheduledExecutorService
to create Threads for rate limitation handling of the createdWebhookClient
!
This allows changing thread information such as name without having to create your own executor.
-
-
-
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 webhooktoken
- The authorization token of the target webhook
This is not a bot/client token!- Throws:
java.lang.IllegalArgumentException
- If the provided token isnull
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 ofdiscordapp.com
- Throws:
java.lang.IllegalArgumentException
- If the provided URL isnull
or is incorrectly formatted
-
-
Method Detail
-
setExecutorService
public WebhookClientBuilder setExecutorService(@Nullable java.util.concurrent.ScheduledExecutorService executorService)
TheScheduledExecutorService
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)
TheOkHttpClient
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)
TheOkHttpClient.Builder
that should be used to create theOkHttpClient
of the resultingWebhookClient
!
If not set ornull
this builder will use theDEFAULT_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 defaultScheduledExecutorService
to create Threads for rate limitation handling of the createdWebhookClient
!
This allows changing thread information such as name without having to create your own executor.- Parameters:
factory
- TheThreadFactory
that will be used when noScheduledExecutorService
has been set viasetExecutorService(ScheduledExecutorService)
- Returns:
- The current WebhookClientBuilder for chaining convenience
-
setDaemon
public WebhookClientBuilder setDaemon(boolean isDaemon)
Whether rate limit threads of the createdWebhookClient
should be treated asThread.isDaemon()
or not.
Default: falseThis 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 newWebhookClient
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
-
-