Package discord4j.core.shard
Class DefaultShardingStrategy.Builder
java.lang.Object
discord4j.core.shard.DefaultShardingStrategy.Builder
- Enclosing class:
- DefaultShardingStrategy
A
ShardingStrategy
builder.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Create theShardingStrategy
.count
(int shardCount) Set the shard count parameter.Set a filter to determine which shards should be accepted for identifying to Discord Gateway.indices
(int... shardIndices) Set the list of shard indices to identify to Discord Gateway.Set a generator function to derive aPublisher
of shard indices to identify to Discord Gateway.maxConcurrency
(int maxConcurrency) Set the sharding maximum concurrency to use when identifying to the Discord Gateway, determining the amount of shards that will be concurrently identified.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
count
Set the shard count parameter. Defaults toDefaultShardingStrategy.RECOMMENDED_SHARD_COUNT
. Must not be negative.- Parameters:
shardCount
- the shard count sent to Discord while identifying eachGatewayClient
- Returns:
- this builder
-
indices
Set the list of shard indices to identify to Discord Gateway. Defaults to identifying all shards. Any invocation of this method will also replace the previously set value atindices(Function)
.- Parameters:
shardIndices
- the list of shard indices to identify- Returns:
- this builder
-
indices
public DefaultShardingStrategy.Builder indices(Function<Integer, Publisher<Integer>> shardIndexSource) Set a generator function to derive aPublisher
of shard indices to identify to Discord Gateway. Defaults to identify all shards. Any invocation of this method will also replace the previously set value atindices(int...)
.- Parameters:
shardIndexSource
- the generator function to determine the shards to identify- Returns:
- this builder
-
filter
Set a filter to determine which shards should be accepted for identifying to Discord Gateway. Defaults to connecting to all shards given by shard count.- Parameters:
shardFilter
- aPredicate
forShardInfo
objects. Called for each shard determined bycount(int)
and schedules it for connection if returningtrue
.- Returns:
- this builder
-
maxConcurrency
Set the sharding maximum concurrency to use when identifying to the Discord Gateway, determining the amount of shards that will be concurrently identified. Defaults to 1. You should only change this value if your bot is authorized to use the very large bot sharding system, otherwise you will hit a rate limit on identifying.maxConcurrency
always needs to be a power of 2 and must not be lower than one.- Parameters:
maxConcurrency
- a positive number indicating the amount of shards that can be identified concurrently.- Returns:
- this builder
-
build
Create theShardingStrategy
.- Returns:
- a custom
ShardingStrategy
-