public final class DiscordClientBuilder extends Object
DiscordClient
.
Allows creating a Discord client for a single shard with many configurable options. You can reuse this builder for
sharding as long as you set the setShardIndex(Integer)
and setShardCount(Integer)
options, or setIdentifyOptions(IdentifyOptions)
.
Constructor and Description |
---|
DiscordClientBuilder(String token)
Initialize a new builder with the given token.
|
Modifier and Type | Method and Description |
---|---|
DiscordClient |
build()
Create a client ready to connect to Discord.
|
reactor.core.publisher.FluxProcessor<Event,Event> |
getEventProcessor()
Get the current
FluxProcessor used to queue Discord events in conjunction with EventDispatcher . |
reactor.core.scheduler.Scheduler |
getEventScheduler()
Get the current
Scheduler used to publish events through EventDispatcher . |
discord4j.common.RateLimiter |
getGatewayLimiter()
Get the current
RateLimiter set in this builder. |
discord4j.gateway.GatewayObserver |
getGatewayObserver()
Get the current
GatewayObserver set in this builder. |
discord4j.gateway.IdentifyOptions |
getIdentifyOptions()
Get the current
IdentifyOptions set in this builder. |
Presence |
getInitialPresence()
Get the current
Presence object used when identifying to the Gateway. |
discord4j.common.JacksonResourceProvider |
getJacksonResourceProvider()
Get the current
JacksonResourceProvider , providing an ObjectMapper for serialization and
deserialization of data. |
discord4j.gateway.retry.RetryOptions |
getRetryOptions()
Get the current
RetryOptions set in this builder. |
discord4j.rest.request.RouterFactory |
getRouterFactory()
Get the current
RouterFactory used to create a Router that executes
Discord REST API requests. |
Integer |
getShardCount()
Retrieve the current shard count, can be
null |
Integer |
getShardIndex()
Retrieve the current shard index.
|
discord4j.store.api.service.StoreService |
getStoreService()
Get the current
StoreService factory, used to create Store instances on
login to cache entities. |
String |
getToken()
Retrieve the token set in this builder.
|
reactor.core.scheduler.Scheduler |
getVoiceConnectionScheduler()
Get the current
Scheduler for voice sending tasks. |
DiscordClientBuilder |
setEventProcessor(reactor.core.publisher.FluxProcessor<Event,Event> eventProcessor)
Set a new
FluxProcessor used to queue Discord events in conjunction with EventDispatcher . |
DiscordClientBuilder |
setEventScheduler(reactor.core.scheduler.Scheduler eventScheduler)
Set a new
Scheduler used to publish events through EventDispatcher . |
DiscordClientBuilder |
setGatewayLimiter(discord4j.common.RateLimiter gatewayLimiter)
Set a new
RateLimiter to this builder. |
DiscordClientBuilder |
setGatewayObserver(discord4j.gateway.GatewayObserver gatewayObserver)
Set a new
GatewayObserver to this builder. |
DiscordClientBuilder |
setIdentifyOptions(discord4j.gateway.IdentifyOptions identifyOptions)
Set a new
IdentifyOptions to this builder. |
DiscordClientBuilder |
setInitialPresence(Presence initialPresence)
Set a new
Presence object used when identifying to the Gateway. |
DiscordClientBuilder |
setJacksonResourceProvider(discord4j.common.JacksonResourceProvider jacksonResourceProvider)
Set a new
JacksonResourceProvider to this builder, dedicated to provide an ObjectMapper for
serialization and deserialization of data. |
DiscordClientBuilder |
setRetryOptions(discord4j.gateway.retry.RetryOptions retryOptions)
Set a new
RetryOptions to this builder. |
DiscordClientBuilder |
setRouterFactory(discord4j.rest.request.RouterFactory routerFactory)
Set a new
RouterFactory used to create a Router that executes Discord
REST API requests. |
DiscordClientBuilder |
setShardCount(Integer shardCount)
Change the shard count.
|
DiscordClientBuilder |
setShardIndex(Integer shardIndex)
Change the shard index.
|
DiscordClientBuilder |
setStoreService(discord4j.store.api.service.StoreService storeService)
Set a new
StoreService to this builder, used to create Store instances on
login to cache entities. |
DiscordClientBuilder |
setToken(String token)
Change the token stored in this builder.
|
DiscordClientBuilder |
setVoiceConnectionScheduler(reactor.core.scheduler.Scheduler voiceConnectionScheduler)
Set a new
Scheduler for voice sending tasks. |
public DiscordClientBuilder(String token)
token
- the bot token used to authenticate to Discordpublic String getToken()
public DiscordClientBuilder setToken(String token)
token
- the new bot token@Nullable public Integer getShardIndex()
null
public DiscordClientBuilder setShardIndex(@Nullable Integer shardIndex)
setIdentifyOptions(IdentifyOptions)
.
Validation is only performed during build()
. Make sure the following holds:
0 <= shardIndex < shardCount
shardIndex
- the new shard index, can be set to null
to use the value under
setIdentifyOptions(IdentifyOptions)
if set, or fallback to a default@Nullable public Integer getShardCount()
null
public DiscordClientBuilder setShardCount(@Nullable Integer shardCount)
Validation is only performed during build()
. Make sure the following holds:
0 <= shardIndex < shardCount
shardCount
- the new shard count, can be set to null
to use a default value@Nullable public discord4j.store.api.service.StoreService getStoreService()
StoreService
factory, used to create Store
instances on
login to cache entities.
Can be null
if automatic discovery is to be used.
null
if automatic discovery should be usedpublic DiscordClientBuilder setStoreService(@Nullable discord4j.store.api.service.StoreService storeService)
StoreService
to this builder, used to create Store
instances on
login to cache entities.storeService
- a new StoreService factory, can be null
to enable automatic discovery@Nullable public reactor.core.publisher.FluxProcessor<Event,Event> getEventProcessor()
FluxProcessor
used to queue Discord events in conjunction with EventDispatcher
.
Can be null
if a default EmitterProcessor
is used.null
when using a default valuepublic DiscordClientBuilder setEventProcessor(@Nullable reactor.core.publisher.FluxProcessor<Event,Event> eventProcessor)
FluxProcessor
used to queue Discord events in conjunction with EventDispatcher
.eventProcessor
- a new FluxProcessor used in this builder. Can be left null
if a default
EmitterProcessor
is used@Nullable public reactor.core.scheduler.Scheduler getEventScheduler()
Scheduler
used to publish events through EventDispatcher
.null
when using a default valuepublic DiscordClientBuilder setEventScheduler(@Nullable reactor.core.scheduler.Scheduler eventScheduler)
Scheduler
used to publish events through EventDispatcher
.eventScheduler
- a new Scheduler for event dispatching. Can be null
to use a default value@Nullable public discord4j.common.JacksonResourceProvider getJacksonResourceProvider()
JacksonResourceProvider
, providing an ObjectMapper
for serialization and
deserialization of data.null
when
using a default valuepublic DiscordClientBuilder setJacksonResourceProvider(@Nullable discord4j.common.JacksonResourceProvider jacksonResourceProvider)
JacksonResourceProvider
to this builder, dedicated to provide an ObjectMapper
for
serialization and deserialization of data.jacksonResourceProvider
- the new resource provider for serialization and deserialization, use null
to use a default one@Nullable public discord4j.rest.request.RouterFactory getRouterFactory()
RouterFactory
used to create a Router
that executes
Discord REST API requests.public DiscordClientBuilder setRouterFactory(@Nullable discord4j.rest.request.RouterFactory routerFactory)
RouterFactory
used to create a Router
that executes Discord
REST API requests.
The resulting client will utilize the produced Router for every request. When performing sharding operations, it
is expected that the underlying Router
instance to be shared across shards in
order to properly coordinate rate-limits on global endpoints. For those cases, use
SingleRouterFactory
.
routerFactory
- a new RouterFactory to create a Router that performs API requests. Pass null
to
use a default value@Nullable public Presence getInitialPresence()
Presence
object used when identifying to the Gateway.null
to use the value under
setIdentifyOptions(IdentifyOptions)
if set, or fallback to a defaultpublic DiscordClientBuilder setInitialPresence(@Nullable Presence initialPresence)
Presence
object used when identifying to the Gateway.initialPresence
- the new presence status used for login. Can be null
to use the value under
setIdentifyOptions(IdentifyOptions)
if set, or fallback to a default@Nullable public discord4j.gateway.IdentifyOptions getIdentifyOptions()
IdentifyOptions
set in this builder. IdentifyOptions is a container
object targeted to group all parameters applied on bot login, like shard information, initial status and even
session identifier and sequence required to resume a session.
Options under getShardIndex()
, getShardCount()
and getInitialPresence()
override the
values in this object.
public DiscordClientBuilder setIdentifyOptions(@Nullable discord4j.gateway.IdentifyOptions identifyOptions)
IdentifyOptions
to this builder. IdentifyOptions is a container object
targeted to group all parameters applied on bot login, like shard information, initial status and even session
identifier and sequence required to resume a session.
Options under setShardIndex(Integer)
, setShardCount(Integer)
and
setInitialPresence(Presence)
override the values in this object.
identifyOptions
- the new bot identification options. Can be set to null
to use a default@Nullable public discord4j.gateway.retry.RetryOptions getRetryOptions()
RetryOptions
set in this builder. RetryOptions is an advanced container object to
parameterize the retry policy used in the gateway operations.null
if default is usedpublic DiscordClientBuilder setRetryOptions(@Nullable discord4j.gateway.retry.RetryOptions retryOptions)
RetryOptions
to this builder. RetryOptions is an advanced container object to parameterize
the retry policy used in the gateway operations.retryOptions
- the new retry policy. Can be set to null
to use a default@Nullable public discord4j.gateway.GatewayObserver getGatewayObserver()
GatewayObserver
set in this builder. GatewayObserver is used as a simple event
listener for gateway connection lifecycle. User can be notified of broad lifecycle events like connections,
resumes, reconnects and disconnects but also very specific ones like session sequence updates.null
if default is usedStoreInvalidator
public DiscordClientBuilder setGatewayObserver(@Nullable discord4j.gateway.GatewayObserver gatewayObserver)
GatewayObserver
to this builder. GatewayObserver is used as a simple event listener for
gateway connection lifecycle. User can be notified of broad lifecycle events like connections, resumes,
reconnects and disconnects but also very specific ones like session sequence updates.gatewayObserver
- a new event listener for gateway lifecycle. Can be chained using
GatewayObserver.then(GatewayObserver)
to create a composite of an arbitrary number of listeners. Can
be set to null
to use a default@Nullable public discord4j.common.RateLimiter getGatewayLimiter()
RateLimiter
set in this builder. GatewayLimiter is a rate limiting strategy
dedicated to coordinate actions between shards, like identifying to the gateway.null
if default is usedpublic DiscordClientBuilder setGatewayLimiter(@Nullable discord4j.common.RateLimiter gatewayLimiter)
RateLimiter
to this builder. GatewayLimiter is a rate limiting strategy dedicated to
coordinate actions between shards, like identifying to the gateway.gatewayLimiter
- the current gateway limiter, for shard coordinated login, can be null
for a defaultpublic reactor.core.scheduler.Scheduler getVoiceConnectionScheduler()
Scheduler
for voice sending tasks.public DiscordClientBuilder setVoiceConnectionScheduler(reactor.core.scheduler.Scheduler voiceConnectionScheduler)
Scheduler
for voice sending tasks.voiceConnectionScheduler
- the new scheduler for voice sending tasks, must not be null
public DiscordClient build()
DiscordClient
based on this builder parameters