Class DefaultShardManagerBuilder
ShardManager
implementation.
A single DefaultShardManagerBuilder can be reused multiple times. Each call to build()
creates a new ShardManager
instance using the same information.
- Since:
- 3.4.0
- Author:
- Aljoscha Grebe
-
Method Summary
Modifier and TypeMethodDescriptionaddEventListenerProvider
(IntFunction<Object> listenerProvider) Adds the provided listener provider to the list of listener providers that will be used to create listeners.addEventListenerProviders
(Collection<IntFunction<Object>> listenerProviders) Adds the provided listener providers to the list of listener providers that will be used to create listeners.addEventListeners
(Object... listeners) Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManager
object.addEventListeners
(Collection<Object> listeners) Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManager
object.build()
Builds a newShardManager
instance and uses the provided token to start the login process.build
(boolean login) Builds a newShardManager
instance.static DefaultShardManagerBuilder
create
(String token, Collection<GatewayIntent> intents) Creates a DefaultShardManagerBuilder with the predefined token.static DefaultShardManagerBuilder
create
(String token, GatewayIntent intent, GatewayIntent... intents) Creates a DefaultShardManagerBuilder with the predefined token.static DefaultShardManagerBuilder
create
(Collection<GatewayIntent> intents) Creates a completely empty DefaultShardManagerBuilder with the predefined intents.static DefaultShardManagerBuilder
create
(GatewayIntent intent, GatewayIntent... intents) Creates a completely empty DefaultShardManagerBuilder with the predefined intents.static DefaultShardManagerBuilder
createDefault
(String token) Creates a DefaultShardManagerBuilder with recommended default settings.static DefaultShardManagerBuilder
createDefault
(String token, Collection<GatewayIntent> intents) Creates a DefaultShardManagerBuilder with recommended default settings.static DefaultShardManagerBuilder
createDefault
(String token, GatewayIntent intent, GatewayIntent... intents) Creates a DefaultShardManagerBuilder with recommended default settings.static DefaultShardManagerBuilder
createLight
(String token) Creates a DefaultShardManagerBuilder with low memory profile settings.static DefaultShardManagerBuilder
createLight
(String token, Collection<GatewayIntent> intents) Creates a DefaultShardManagerBuilder with low memory profile settings.static DefaultShardManagerBuilder
createLight
(String token, GatewayIntent intent, GatewayIntent... intents) Creates a DefaultShardManagerBuilder with low memory profile settings.disableCache
(Collection<CacheFlag> flags) Disable specific cache flags.disableCache
(CacheFlag flag, CacheFlag... flags) Disable specific cache flags.disableIntents
(Collection<GatewayIntent> intents) Disable the specifiedGatewayIntents
.disableIntents
(GatewayIntent intent, GatewayIntent... intents) Disable the specifiedGatewayIntents
.enableCache
(Collection<CacheFlag> flags) Enable specific cache flags.enableCache
(CacheFlag flag, CacheFlag... flags) Enable specific cache flags.enableIntents
(Collection<GatewayIntent> intents) Enable the specifiedGatewayIntents
.enableIntents
(GatewayIntent intent, GatewayIntent... intents) Enable the specifiedGatewayIntents
.removeEventListenerProvider
(IntFunction<Object> listenerProvider) Removes the provided listener provider from the list of listener providers.removeEventListenerProviders
(Collection<IntFunction<Object>> listenerProviders) Removes all provided listener providers from the list of listener providers.removeEventListeners
(Object... listeners) Removes all provided listeners from the list of listeners.removeEventListeners
(Collection<Object> listeners) Removes all provided listeners from the list of listeners.setActivity
(Activity activity) Sets theActivity
for our session.setActivityProvider
(IntFunction<? extends Activity> activityProvider) Sets theActivity
for our session.Sets theScheduledExecutorService
used by the audio WebSocket connection.setAudioPool
(ScheduledExecutorService pool, boolean automaticShutdown) Sets theScheduledExecutorService
used by the audio WebSocket connection.setAudioPoolProvider
(ThreadPoolProvider<? extends ScheduledExecutorService> provider) Sets theScheduledExecutorService
used by the audio WebSocket connection.setAudioSendFactory
(IAudioSendFactory factory) Changes the factory used to createIAudioSendSystem
objects which handle the sending loop for audio packets.setAutoReconnect
(boolean autoReconnect) Sets whether or not JDA should try to reconnect if a connection-error is encountered.setBulkDeleteSplittingEnabled
(boolean enabled) If enabled, JDA will separate the bulk delete event into individual delete events, but this isn't as efficient as handling a single event would be.setCallbackPool
(ExecutorService executor) Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.setCallbackPool
(ExecutorService executor, boolean automaticShutdown) Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.setCallbackPoolProvider
(ThreadPoolProvider<? extends ExecutorService> provider) Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.setChunkingFilter
(ChunkingFilter filter) TheChunkingFilter
to filter which guilds should use member chunking.setCompression
(Compression compression) Sets the compression algorithm used with the gateway connection, this will decrease the amount of used bandwidth for the running bot instance for the cost of a few extra cycles for decompression.setContextEnabled
(boolean enable) Whether JDA should use a synchronized MDC context for all of its controlled threads.setContextMap
(IntFunction<? extends ConcurrentMap<String, String>> provider) Sets theMDC
mappings provider to use in JDA.setDisabledIntents
(Collection<GatewayIntent> intents) Configures which events will be disabled.setDisabledIntents
(GatewayIntent intent, GatewayIntent... intents) Configures which events will be disabled.setEnabledIntents
(Collection<GatewayIntent> intents) Configures which events will be enabled.setEnabledIntents
(GatewayIntent intent, GatewayIntent... intents) Configures which events will be enabled.setEnableShutdownHook
(boolean enable) Enables/Disables the use of a Shutdown hook to clean up the ShardManager and it's JDA instances.setEventManagerProvider
(IntFunction<? extends IEventManager> eventManagerProvider) Sets a provider to change the internally used EventManager.setEventPassthrough
(boolean enable) Whether JDA should store the rawDataObject
for every discord event, accessible throughgetRawData()
.setEventPool
(ExecutorService executor) Sets theExecutorService
that should be used by the event proxy to schedule events.setEventPool
(ExecutorService executor, boolean automaticShutdown) Sets theExecutorService
that should be used by the event proxy to schedule events.setEventPoolProvider
(ThreadPoolProvider<? extends ExecutorService> provider) Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.setGatewayEncoding
(GatewayEncoding encoding) Choose whichGatewayEncoding
JDA should use.Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.setGatewayPool
(ScheduledExecutorService pool, boolean automaticShutdown) Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.setGatewayPoolProvider
(ThreadPoolProvider<? extends ScheduledExecutorService> provider) Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.setHttpClient
(okhttp3.OkHttpClient client) Sets theOkHttpClient
that will be used by JDAs requester.setHttpClientBuilder
(okhttp3.OkHttpClient.Builder builder) Sets theBuilder
that will be used by JDA's requester.setIdle
(boolean idle) Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean)
.setIdleProvider
(IntFunction<Boolean> idleProvider) Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean)
.setLargeThreshold
(int threshold) Decides the total number of members at which a guild should start to use lazy loading.setMaxBufferSize
(int bufferSize) The maximum size, in bytes, of the buffer used for decompressing discord payloads.setMaxReconnectDelay
(int maxReconnectDelay) Sets the maximum amount of time that JDA will back off to wait when attempting to reconnect the MainWebsocket.Configure the member caching policy.Sets theExecutorService
that should be used in the JDA request handler.setRateLimitElastic
(ExecutorService pool, boolean automaticShutdown) Sets theExecutorService
that should be used in the JDA request handler.setRateLimitElasticProvider
(ThreadPoolProvider<? extends ExecutorService> provider) Sets theExecutorService
that should be used in the JDA request handler.Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler.setRateLimitScheduler
(ScheduledExecutorService pool, boolean automaticShutdown) Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler.setRateLimitSchedulerProvider
(ThreadPoolProvider<? extends ScheduledExecutorService> provider) Sets theScheduledExecutorService
provider that should be used in the JDA rate-limit handler.setRawEventsEnabled
(boolean enable) Whether JDA should fireRawGatewayEvent
for every discord event.setRequestTimeoutRetry
(boolean retryOnTimeout) Whether the Requester should retry when aSocketTimeoutException
occurs.setRestConfig
(RestConfig config) CustomRestConfig
to use.setRestConfigProvider
(IntFunction<? extends RestConfig> provider) CustomRestConfig
to use.setSessionController
(SessionController controller) Sets theSessionController
for the resulting ShardManager instance.setShards
(int... shardIds) Sets the list of shards theDefaultShardManager
should contain.setShards
(int minShardId, int maxShardId) Sets the range of shards theDefaultShardManager
should contain.setShards
(Collection<Integer> shardIds) Sets the range of shards theDefaultShardManager
should contain.setShardsTotal
(int shardsTotal) This will set the total amount of shards theDefaultShardManager
should use.setStatus
(OnlineStatus status) Sets theOnlineStatus
our connection will display.setStatusProvider
(IntFunction<OnlineStatus> statusProvider) Sets theOnlineStatus
our connection will display.setThreadFactory
(ThreadFactory threadFactory) Sets theThreadFactory
that will be used by the internal executor of the ShardManager.Sets the token that will be used by theShardManager
instance to log in whenbuild()
is called.setUseShutdownNow
(boolean useShutdownNow) Whether theShardManager
should useJDA#shutdownNow()
instead ofJDA#shutdown()
to shutdown it's shards.setVoiceDispatchInterceptor
(VoiceDispatchInterceptor interceptor) Configures a custom voice dispatch handler which handles audio connections.setWebsocketFactory
(WebSocketFactory factory) Sets theWebSocketFactory
that will be used by JDA's websocket client.
-
Method Details
-
createDefault
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createDefault(@Nullable String token) Creates a DefaultShardManagerBuilder with recommended default settings.
Note that these defaults can potentially change in the future.setMemberCachePolicy(MemberCachePolicy)
is set toMemberCachePolicy.DEFAULT
setChunkingFilter(ChunkingFilter)
is set toChunkingFilter.NONE
setEnabledIntents(Collection)
is set toGatewayIntent.DEFAULT
- This disables
CacheFlag.ACTIVITY
andCacheFlag.CLIENT_STATUS
- Parameters:
token
- The bot token to use- Returns:
- The new DefaultShardManagerBuilder
- See Also:
-
createDefault
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createDefault(@Nullable String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Creates a DefaultShardManagerBuilder with recommended default settings.
Note that these defaults can potentially change in the future.setMemberCachePolicy(MemberCachePolicy)
is set toMemberCachePolicy.DEFAULT
setChunkingFilter(ChunkingFilter)
is set toChunkingFilter.NONE
- This disables
CacheFlag.ACTIVITY
andCacheFlag.CLIENT_STATUS
You can omit intents in this method to use
GatewayIntent.DEFAULT
and enable additional intents withenableIntents(Collection)
.If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
token
- The bot token to useintent
- The intent to enableintents
- Any other intents to enable- Returns:
- The new DefaultShardManagerBuilder
- Throws:
IllegalArgumentException
- If provided with null intents
-
createDefault
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createDefault(@Nullable String token, @Nonnull Collection<GatewayIntent> intents) Creates a DefaultShardManagerBuilder with recommended default settings.
Note that these defaults can potentially change in the future.setMemberCachePolicy(MemberCachePolicy)
is set toMemberCachePolicy.DEFAULT
setChunkingFilter(ChunkingFilter)
is set toChunkingFilter.NONE
- This disables
CacheFlag.ACTIVITY
andCacheFlag.CLIENT_STATUS
You can omit intents in this method to use
GatewayIntent.DEFAULT
and enable additional intents withenableIntents(Collection)
.If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
token
- The bot token to useintents
- The intents to enable- Returns:
- The new DefaultShardManagerBuilder
- Throws:
IllegalArgumentException
- If provided with null intents
-
createLight
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createLight(@Nullable String token) Creates a DefaultShardManagerBuilder with low memory profile settings.
Note that these defaults can potentially change in the future.setEnabledIntents(Collection)
is set toGatewayIntent.DEFAULT
setMemberCachePolicy(MemberCachePolicy)
is set toMemberCachePolicy.NONE
setChunkingFilter(ChunkingFilter)
is set toChunkingFilter.NONE
- This disables all existing
CacheFlags
- Parameters:
token
- The bot token to use- Returns:
- The new DefaultShardManagerBuilder
- See Also:
-
createLight
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createLight(@Nullable String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Creates a DefaultShardManagerBuilder with low memory profile settings.
Note that these defaults can potentially change in the future.setMemberCachePolicy(MemberCachePolicy)
is set toMemberCachePolicy.NONE
setChunkingFilter(ChunkingFilter)
is set toChunkingFilter.NONE
- This disables all existing
CacheFlags
You can omit intents in this method to use
GatewayIntent.DEFAULT
and enable additional intents withenableIntents(Collection)
.If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
token
- The bot token to useintent
- The first intent to useintents
- The other gateway intents to use- Returns:
- The new DefaultShardManagerBuilder
-
createLight
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createLight(@Nullable String token, @Nonnull Collection<GatewayIntent> intents) Creates a DefaultShardManagerBuilder with low memory profile settings.
Note that these defaults can potentially change in the future.setMemberCachePolicy(MemberCachePolicy)
is set toMemberCachePolicy.NONE
setChunkingFilter(ChunkingFilter)
is set toChunkingFilter.NONE
- This disables all existing
CacheFlags
You can omit intents in this method to use
GatewayIntent.DEFAULT
and enable additional intents withenableIntents(Collection)
.If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
token
- The bot token to useintents
- The gateway intents to use- Returns:
- The new DefaultShardManagerBuilder
-
create
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder create(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Creates a completely empty DefaultShardManagerBuilder with the predefined intents.
You can useDefaultShardManagerBuilder.create(EnumSet.noneOf(GatewayIntent.class))
to disable all intents.
If you use this, you need to set the token usingsetToken(String)
before callingbuild()
If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
intent
- The first intentintents
- The gateway intents to use- Returns:
- The DefaultShardManagerBuilder instance
- Throws:
IllegalArgumentException
- If the provided intents are null- See Also:
-
create
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder create(@Nonnull Collection<GatewayIntent> intents) Creates a completely empty DefaultShardManagerBuilder with the predefined intents.
If you use this, you need to set the token usingsetToken(String)
before callingbuild()
If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
intents
- The gateway intents to use- Returns:
- The DefaultShardManagerBuilder instance
- Throws:
IllegalArgumentException
- If the provided intents are null- See Also:
-
create
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder create(@Nullable String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Creates a DefaultShardManagerBuilder with the predefined token.
You can useDefaultShardManagerBuilder.create(token, EnumSet.noneOf(GatewayIntent.class))
to disable all intents.If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
token
- The bot token to useintent
- The first gateway intent to useintents
- Additional gateway intents to use- Returns:
- The DefaultShardManagerBuilder instance
- Throws:
IllegalArgumentException
- If the provided intents are null- See Also:
-
create
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder create(@Nullable String token, @Nonnull Collection<GatewayIntent> intents) Creates a DefaultShardManagerBuilder with the predefined token.If you don't enable certain intents, the cache will be disabled. For instance, if the
GUILD_MEMBERS
intent is disabled, then members will only be cached when a voice state is available. If bothGUILD_MEMBERS
andGUILD_VOICE_STATES
are disabled then no members will be cached.The individual
CacheFlags
will also be disabled if therequired intent
is not enabled.- Parameters:
token
- The bot token to useintents
- The gateway intents to use- Returns:
- The DefaultShardManagerBuilder instance
- Throws:
IllegalArgumentException
- If the provided intents are null- See Also:
-
setGatewayEncoding
Choose whichGatewayEncoding
JDA should use.- Parameters:
encoding
- TheGatewayEncoding
(default: JSON)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If null is provided- Since:
- 4.2.1
-
setRawEventsEnabled
- Parameters:
enable
- True, if JDA should fireRawGatewayEvent
.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
-
setEventPassthrough
Whether JDA should store the rawDataObject
for every discord event, accessible throughgetRawData()
.
You can expect to receive the full gateway message payload, including sequence, event name and dispatch type of the events
You can read more about payloads here and the different events here.
Warning: be aware that enabling this could consume a lot of memory if your event objects have a long lifetime.
Default:false
- Parameters:
enable
- True, if JDA should add the rawDataObject
to every discord event.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setRestConfigProvider
@Nonnull public DefaultShardManagerBuilder setRestConfigProvider(@Nonnull IntFunction<? extends RestConfig> provider) CustomRestConfig
to use.
This can be used to customize how rate-limits are handled and configure a custom http proxy.- Parameters:
provider
- TheRestConfig
provider to use- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If null is provided
-
setRestConfig
CustomRestConfig
to use.
This can be used to customize how rate-limits are handled and configure a custom http proxy.- Parameters:
config
- TheRestConfig
to use- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If null is provided
-
enableCache
Enable specific cache flags.
This will not disable any currently set cache flags.- Parameters:
flags
- TheCacheFlags
to enable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
enableCache
@Nonnull public DefaultShardManagerBuilder enableCache(@Nonnull CacheFlag flag, @Nonnull CacheFlag... flags) Enable specific cache flags.
This will not disable any currently set cache flags.- Parameters:
flag
-CacheFlag
to enableflags
- Other flags to enable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
disableCache
Disable specific cache flags.
This will not enable any currently unset cache flags.- Parameters:
flags
- TheCacheFlags
to disable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
disableCache
@Nonnull public DefaultShardManagerBuilder disableCache(@Nonnull CacheFlag flag, @Nonnull CacheFlag... flags) Disable specific cache flags.
This will not enable any currently unset cache flags.- Parameters:
flag
-CacheFlag
to disableflags
- Other flags to disable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
setMemberCachePolicy
Configure the member caching policy. This will decide whether to cache a member (and its respective user).
All members are cached by default. If a guild is enabled for chunking, all members will be cached for it.You can use this to define a custom caching policy that will greatly improve memory usage.
It is not recommended to disable
GatewayIntent.GUILD_MEMBERS
when usingMemberCachePolicy.ALL
as the members cannot be removed from cache by a leave event without this intent.Example
public void configureCache(DefaultShardManagerBuilder builder) { // Cache members who are in a voice channel MemberCachePolicy policy = MemberCachePolicy.VOICE; // Cache members who are in a voice channel // AND are also online policy = policy.and(MemberCachePolicy.ONLINE); // Cache members who are in a voice channel // AND are also online // OR are the owner of the guild policy = policy.or(MemberCachePolicy.OWNER); // Cache members who have a role with the name "Moderator" policy = (member) -> member.getRoles().stream().map(Role::getName).anyMatch("Moderator"::equals); builder.setMemberCachePolicy(policy); }
- Parameters:
policy
- TheMemberCachePolicy
or null to use defaultMemberCachePolicy.ALL
- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.0
- See Also:
-
setSessionController
@Nonnull public DefaultShardManagerBuilder setSessionController(@Nullable SessionController controller) Sets theSessionController
for the resulting ShardManager instance. This can be used to sync behaviour and state between shards of a bot and should be one and the same instance on all builders for the shards.- Parameters:
controller
- TheSessionController
to use- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setVoiceDispatchInterceptor
@Nonnull public DefaultShardManagerBuilder setVoiceDispatchInterceptor(@Nullable VoiceDispatchInterceptor interceptor) Configures a custom voice dispatch handler which handles audio connections.- Parameters:
interceptor
- The new voice dispatch handler, or null to use the default- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
- See Also:
-
setContextMap
@Nonnull public DefaultShardManagerBuilder setContextMap(@Nullable IntFunction<? extends ConcurrentMap<String, String>> provider) Sets theMDC
mappings provider to use in JDA.
If sharding is enabled JDA will automatically add ajda.shard
context with the format[SHARD_ID / TOTAL]
whereSHARD_ID
andTOTAL
are the shard configuration. Additionally it will provide context for the id viajda.shard.id
and the total viajda.shard.total
.The manager will call this with a shardId and it is recommended to provide a different context map for each shard!
This automatically switchessetContextEnabled(boolean)
to true if the provided function is not null!- Parameters:
provider
- The provider for modifiable context maps to use in JDA, ornull
to reset- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setContextEnabled
Whether JDA should use a synchronized MDC context for all of its controlled threads.
Default:true
- Parameters:
enable
- True, if JDA should provide an MDC context map- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setCompression
Sets the compression algorithm used with the gateway connection, this will decrease the amount of used bandwidth for the running bot instance for the cost of a few extra cycles for decompression. Compression can be entirely disabled by setting this toCompression.NONE
.
Default:Compression.ZLIB
We recommend to keep this on the default unless you have issues with the decompression
This mode might become obligatory in a future version, do not rely on this switch to stay.- Parameters:
compression
- The compression algorithm to use for the gateway connection- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
addEventListeners
Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManager
object.
This uses theInterfacedEventListener
by default.
To switch to theAnnotatedEventManager
, usesetEventManagerProvider(id -> new AnnotatedEventManager())
.Note: When using the
InterfacedEventListener
(default), given listener(s) must be instance ofEventListener
!- Parameters:
listeners
- The listener(s) to add to the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
addEventListeners
Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManager
object.
This uses theInterfacedEventListener
by default.
To switch to theAnnotatedEventManager
, usesetEventManager(id -> new AnnotatedEventManager())
.Note: When using the
InterfacedEventListener
(default), given listener(s) must be instance ofEventListener
!- Parameters:
listeners
- The listener(s) to add to the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
removeEventListeners
Removes all provided listeners from the list of listeners.- Parameters:
listeners
- The listener(s) to remove from the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
removeEventListeners
@Nonnull public DefaultShardManagerBuilder removeEventListeners(@Nonnull Collection<Object> listeners) Removes all provided listeners from the list of listeners.- Parameters:
listeners
- The listener(s) to remove from the list.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
addEventListenerProvider
@Nonnull public DefaultShardManagerBuilder addEventListenerProvider(@Nonnull IntFunction<Object> listenerProvider) Adds the provided listener provider to the list of listener providers that will be used to create listeners. On shard creation (including shard restarts) the provider will have the shard id applied and must return a listener, which will be used, along all other listeners, to populate the listeners of the JDA object of that shard.
This uses theInterfacedEventListener
by default.
To switch to theAnnotatedEventManager
, usesetEventManager(id -> new AnnotatedEventManager())
.Note: When using the
InterfacedEventListener
(default), given listener(s) must be instance ofEventListener
!- Parameters:
listenerProvider
- The listener provider to add to the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
addEventListenerProviders
@Nonnull public DefaultShardManagerBuilder addEventListenerProviders(@Nonnull Collection<IntFunction<Object>> listenerProviders) Adds the provided listener providers to the list of listener providers that will be used to create listeners. On shard creation (including shard restarts) each provider will have the shard id applied and must return a listener, which will be used, along all other listeners, to populate the listeners of the JDA object of that shard.
This uses theInterfacedEventListener
by default.
To switch to theAnnotatedEventManager
, usesetEventManager(id -> new AnnotatedEventManager())
.Note: When using the
InterfacedEventListener
(default), given listener(s) must be instance ofEventListener
!- Parameters:
listenerProviders
- The listener provider to add to the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
removeEventListenerProvider
@Nonnull public DefaultShardManagerBuilder removeEventListenerProvider(@Nonnull IntFunction<Object> listenerProvider) Removes the provided listener provider from the list of listener providers.- Parameters:
listenerProvider
- The listener provider to remove from the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
removeEventListenerProviders
@Nonnull public DefaultShardManagerBuilder removeEventListenerProviders(@Nonnull Collection<IntFunction<Object>> listenerProviders) Removes all provided listener providers from the list of listener providers.- Parameters:
listenerProviders
- The listener provider(s) to remove from the list of listener providers.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setAudioSendFactory
Changes the factory used to createIAudioSendSystem
objects which handle the sending loop for audio packets.
By default, JDA usesDefaultSendFactory
.- Parameters:
factory
- The newIAudioSendFactory
to be used when creating newIAudioSendSystem
objects.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setAutoReconnect
Sets whether or not JDA should try to reconnect if a connection-error is encountered.
This will use an incremental reconnect (timeouts are increased each time an attempt fails).Default: true (enabled)
- Parameters:
autoReconnect
- If true - enables autoReconnect- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setBulkDeleteSplittingEnabled
If enabled, JDA will separate the bulk delete event into individual delete events, but this isn't as efficient as handling a single event would be. It is recommended that BulkDelete Splitting be disabled and that the developer should instead handle theMessageBulkDeleteEvent
.Default: true (enabled)
- Parameters:
enabled
- True - The MESSAGE_DELETE_BULK will be split into multiple individual MessageDeleteEvents.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setEnableShutdownHook
Enables/Disables the use of a Shutdown hook to clean up the ShardManager and it's JDA instances.
When the Java program closes shutdown hooks are run. This is used as a last-second cleanup attempt by JDA to properly close connections.Default: true (enabled)
- Parameters:
enable
- True (default) - use shutdown hook to clean up the ShardManager and it's JDA instances if the Java program is closed.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setEventManagerProvider
@Nonnull public DefaultShardManagerBuilder setEventManagerProvider(@Nonnull IntFunction<? extends IEventManager> eventManagerProvider) Sets a provider to change the internally used EventManager.
There are 2 provided Implementations:InterfacedEventManager
which uses the InterfaceEventListener
(tip: use theListenerAdapter
).
This is the default EventManager.AnnotatedEventManager
which uses the Annotation@SubscribeEvent
to mark the methods that listen for events.
You can also create your own EventManager (SeeIEventManager
).- Parameters:
eventManagerProvider
- A supplier for the newIEventManager
to use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setActivity
Sets theActivity
for our session.
This value can be changed at any time in thePresence
from a JDA instance.Hint: You can create an
Activity
object usingActivity.playing(String)
orActivity.streaming(String, String)
Activity.streaming(String, String)}.- Parameters:
activity
- An instance ofActivity
(null allowed)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setActivityProvider
@Nonnull public DefaultShardManagerBuilder setActivityProvider(@Nullable IntFunction<? extends Activity> activityProvider) Sets theActivity
for our session.
This value can be changed at any time in thePresence
from a JDA instance.Hint: You can create an
Activity
object usingActivity.playing(String)
orActivity.streaming(String, String)
.- Parameters:
activityProvider
- An instance ofActivity
(null allowed)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setIdle
Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean)
.- Parameters:
idle
- boolean value that will be provided with our IDENTIFY packages to mark our sessions as afk or not. (default false)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setIdleProvider
@Nonnull public DefaultShardManagerBuilder setIdleProvider(@Nullable IntFunction<Boolean> idleProvider) Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean)
.- Parameters:
idleProvider
- boolean value that will be provided with our IDENTIFY packages to mark our sessions as afk or not. (default false)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setStatus
Sets theOnlineStatus
our connection will display.
This value can be changed at any time in thePresence
from a JDA instance.- Parameters:
status
- Not-null OnlineStatus (default online)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- if the provided OnlineStatus is null orUNKNOWN
- See Also:
-
setStatusProvider
@Nonnull public DefaultShardManagerBuilder setStatusProvider(@Nullable IntFunction<OnlineStatus> statusProvider) Sets theOnlineStatus
our connection will display.
This value can be changed at any time in thePresence
from a JDA instance.- Parameters:
statusProvider
- Not-null OnlineStatus (default online)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- if the provided OnlineStatus is null orUNKNOWN
- See Also:
-
setThreadFactory
Sets theThreadFactory
that will be used by the internal executor of the ShardManager.Note: This will not affect Threads created by any JDA instance.
- Parameters:
threadFactory
- The ThreadFactory ornull
to reset to the default value.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setHttpClientBuilder
@Nonnull public DefaultShardManagerBuilder setHttpClientBuilder(@Nullable okhttp3.OkHttpClient.Builder builder) Sets theBuilder
that will be used by JDA's requester. This can be used to set things such as connection timeout and proxy.- Parameters:
builder
- The newOkHttpClient.Builder
to use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setHttpClient
Sets theOkHttpClient
that will be used by JDAs requester.
This can be used to set things such as connection timeout and proxy.- Parameters:
client
- The newOkHttpClient
to use- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitScheduler
@Nonnull public DefaultShardManagerBuilder setRateLimitScheduler(@Nullable ScheduledExecutorService pool) Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.
This will override the rate-limit pool provider set fromsetRateLimitSchedulerProvider(ThreadPoolProvider)
.
This automatically disables the automatic shutdown of the rate-limit pool, you can enable it usingsetRateLimiPool(executor, true)
This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. Besides that it is also used by planned execution for
RestAction.queueAfter(long, TimeUnit)
and similar methods. Requests are handed off to theelastic pool
for blocking execution.Default: Shared
ScheduledThreadPoolExecutor
with (2 *
log(shard_total
)) threads.- Parameters:
pool
- The thread-pool to use for rate-limit handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitScheduler
@Nonnull public DefaultShardManagerBuilder setRateLimitScheduler(@Nullable ScheduledExecutorService pool, boolean automaticShutdown) Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.
This will override the rate-limit pool provider set fromsetRateLimitSchedulerProvider(ThreadPoolProvider)
.This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. Besides that it is also used by planned execution for
RestAction.queueAfter(long, TimeUnit)
and similar methods. Requests are handed off to theelastic pool
for blocking execution.Default: Shared
ScheduledThreadPoolExecutor
with (2 *
log(shard_total
)) threads.- Parameters:
pool
- The thread-pool to use for rate-limit handlingautomaticShutdown
- WhetherJDA.shutdown()
should automatically shutdown this pool- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitSchedulerProvider
@Nonnull public DefaultShardManagerBuilder setRateLimitSchedulerProvider(@Nullable ThreadPoolProvider<? extends ScheduledExecutorService> provider) Sets theScheduledExecutorService
provider that should be used in the JDA rate-limit handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.This is used mostly by the Rate-Limiter to handle backoff delays by using scheduled executions. Besides that it is also used by planned execution for
RestAction.queueAfter(long, TimeUnit)
and similar methods. Requests are handed off to theelastic pool
for blocking execution.Default: Shared
ScheduledThreadPoolExecutor
with (2 *
log(shard_total
)) threads.- Parameters:
provider
- The thread-pool provider to use for rate-limit handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitElastic
Sets theExecutorService
that should be used in the JDA request handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.
This will override the rate-limit pool provider set fromsetRateLimitElasticProvider(ThreadPoolProvider)
.
This automatically disables the automatic shutdown of the rate-limit elastic pool, you can enable it usingsetRateLimitElastic(executor, true)
This is used mostly by the Rate-Limiter to execute the blocking HTTP requests at runtime.
Default:
Executors.newCachedThreadPool()
shared between all shards.- Parameters:
pool
- The thread-pool to use for executing http requests- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitElastic
@Nonnull public DefaultShardManagerBuilder setRateLimitElastic(@Nullable ExecutorService pool, boolean automaticShutdown) Sets theExecutorService
that should be used in the JDA request handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.
This will override the rate-limit pool provider set fromsetRateLimitElasticProvider(ThreadPoolProvider)
.
This automatically disables the automatic shutdown of the rate-limit elastic pool, you can enable it usingsetRateLimitElastic(executor, true)
This is used mostly by the Rate-Limiter to execute the blocking HTTP requests at runtime.
Default:
Executors.newCachedThreadPool()
shared between all shards.- Parameters:
pool
- The thread-pool to use for executing http requestsautomaticShutdown
- WhetherJDA.shutdown()
should automatically shutdown this pool- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitElasticProvider
@Nonnull public DefaultShardManagerBuilder setRateLimitElasticProvider(@Nullable ThreadPoolProvider<? extends ExecutorService> provider) Sets theExecutorService
that should be used in the JDA request handler. Changing this can drastically change the JDA behavior for RestAction execution and should be handled carefully. Only change this pool if you know what you're doing.This is used mostly by the Rate-Limiter to execute the blocking HTTP requests at runtime.
Default:
Executors.newCachedThreadPool()
shared between all shards.- Parameters:
provider
- The thread-pool provider to use for executing http requests- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPool
Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.
Only change this pool if you know what you're doing.
This will override the worker pool provider set fromsetGatewayPoolProvider(ThreadPoolProvider)
.
This automatically disables the automatic shutdown of the main-ws pools, you can enable it usingsetGatewayPoolProvider(pool, true)
This is used to send various forms of session updates such as:
- Voice States - (Dis-)Connecting from channels
- Presence - Changing current activity or online status
- Guild Setup - Requesting Members of newly joined guilds
- Heartbeats - Regular updates to keep the connection alive (usually once a minute)
Default: Shared
ScheduledThreadPoolExecutor
with (log
(shard_total
)) threads.- Parameters:
pool
- The thread-pool to use for main WebSocket workers- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPool
@Nonnull public DefaultShardManagerBuilder setGatewayPool(@Nullable ScheduledExecutorService pool, boolean automaticShutdown) Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.
Only change this pool if you know what you're doing.
This will override the worker pool provider set fromsetGatewayPoolProvider(ThreadPoolProvider)
.This is used to send various forms of session updates such as:
- Voice States - (Dis-)Connecting from channels
- Presence - Changing current activity or online status
- Guild Setup - Requesting Members of newly joined guilds
- Heartbeats - Regular updates to keep the connection alive (usually once a minute)
Default: Shared
ScheduledThreadPoolExecutor
with (log
(shard_total
)) threads.- Parameters:
pool
- The thread-pool to use for main WebSocket workersautomaticShutdown
- WhetherJDA.shutdown()
should automatically shutdown this pool- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPoolProvider
@Nonnull public DefaultShardManagerBuilder setGatewayPoolProvider(@Nullable ThreadPoolProvider<? extends ScheduledExecutorService> provider) Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.
Only change this pool if you know what you're doing.This is used to send various forms of session updates such as:
- Voice States - (Dis-)Connecting from channels
- Presence - Changing current activity or online status
- Guild Setup - Requesting Members of newly joined guilds
- Heartbeats - Regular updates to keep the connection alive (usually once a minute)
Default: Shared
ScheduledThreadPoolExecutor
with (log
(shard_total
)) threads.- Parameters:
provider
- The thread-pool provider to use for main WebSocket workers- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setCallbackPool
Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks. By default JDA will useForkJoinPool.commonPool()
Only change this pool if you know what you're doing.
This automatically disables the automatic shutdown of the callback pools, you can enable it usingsetCallbackPool(executor, true)
This is used to handle callbacks of
RestAction.queue()
, similarly it is used to finishRestAction.submit()
andRestAction.complete()
tasks which build on queue.Default:
ForkJoinPool.commonPool()
- Parameters:
executor
- The thread-pool to use for callback handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setCallbackPool
@Nonnull public DefaultShardManagerBuilder setCallbackPool(@Nullable ExecutorService executor, boolean automaticShutdown) Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks. By default JDA will useForkJoinPool.commonPool()
Only change this pool if you know what you're doing.This is used to handle callbacks of
RestAction.queue()
, similarly it is used to finishRestAction.submit()
andRestAction.complete()
tasks which build on queue.Default:
ForkJoinPool.commonPool()
- Parameters:
executor
- The thread-pool to use for callback handlingautomaticShutdown
- WhetherJDA.shutdown()
should automatically shutdown this pool- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setCallbackPoolProvider
@Nonnull public DefaultShardManagerBuilder setCallbackPoolProvider(@Nullable ThreadPoolProvider<? extends ExecutorService> provider) Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks. By default JDA will useForkJoinPool.commonPool()
Only change this pool if you know what you're doing.This is used to handle callbacks of
RestAction.queue()
, similarly it is used to finishRestAction.submit()
andRestAction.complete()
tasks which build on queue.Default:
ForkJoinPool.commonPool()
- Parameters:
provider
- The thread-pool provider to use for callback handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setEventPool
Sets theExecutorService
that should be used by the event proxy to schedule events. This will be done on the calling thread by default.The executor will not be shutdown automatically when the shard is shutdown. To shut it down automatically use
setEventPool(ExecutorService, boolean)
.Default: Disabled
- Parameters:
executor
- The executor for the event proxy, or null to use calling thread- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.0
-
setEventPool
@Nonnull public DefaultShardManagerBuilder setEventPool(@Nullable ExecutorService executor, boolean automaticShutdown) Sets theExecutorService
that should be used by the event proxy to schedule events. This will be done on the calling thread by default.Default: Disabled
- Parameters:
executor
- The executor for the event proxy, or null to use calling threadautomaticShutdown
- True, if the executor should be shutdown when JDA shuts down- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.0
-
setEventPoolProvider
@Nonnull public DefaultShardManagerBuilder setEventPoolProvider(@Nullable ThreadPoolProvider<? extends ExecutorService> provider) Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks. By default JDA will useForkJoinPool.commonPool()
Only change this pool if you know what you're doing.This is used to handle callbacks of
RestAction.queue()
, similarly it is used to finishRestAction.submit()
andRestAction.complete()
tasks which build on queue.Default: Disabled
- Parameters:
provider
- The thread-pool provider to use for callback handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.0
-
setAudioPool
Sets theScheduledExecutorService
used by the audio WebSocket connection. Used for sending keepalives and closing the connection.
Only change this pool if you know what you're doing.Default:
ScheduledThreadPoolExecutor
with 1 thread- Parameters:
pool
- The thread-pool to use for the audio WebSocket- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.1
-
setAudioPool
@Nonnull public DefaultShardManagerBuilder setAudioPool(@Nullable ScheduledExecutorService pool, boolean automaticShutdown) Sets theScheduledExecutorService
used by the audio WebSocket connection. Used for sending keepalives and closing the connection.
Only change this pool if you know what you're doing.Default:
ScheduledThreadPoolExecutor
with 1 thread- Parameters:
pool
- The thread-pool to use for the audio WebSocketautomaticShutdown
- True, if the executor should be shutdown when JDA shuts down- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.1
-
setAudioPoolProvider
@Nonnull public DefaultShardManagerBuilder setAudioPoolProvider(@Nullable ThreadPoolProvider<? extends ScheduledExecutorService> provider) Sets theScheduledExecutorService
used by the audio WebSocket connection. Used for sending keepalives and closing the connection.
Only change this pool if you know what you're doing.Default:
ScheduledThreadPoolExecutor
with 1 thread- Parameters:
provider
- The thread-pool provider to use for the audio WebSocket- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.1
-
setMaxReconnectDelay
Sets the maximum amount of time that JDA will back off to wait when attempting to reconnect the MainWebsocket.
Provided value must be 32 or greater.Default:
900
- Parameters:
maxReconnectDelay
- The maximum amount of time that JDA will wait between reconnect attempts in seconds.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- Thrown if the providedmaxReconnectDelay
is less than 32.
-
setRequestTimeoutRetry
Whether the Requester should retry when aSocketTimeoutException
occurs.
Default:true
This value can be changed at any time with
JDA.setRequestTimeoutRetry(boolean)
!- Parameters:
retryOnTimeout
- True, if the Request should retry once on a socket timeout- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setShards
Sets the list of shards theDefaultShardManager
should contain.This does not have any effect if the total shard count is set to
-1
(get recommended shards from discord).- Parameters:
shardIds
- The list of shard ids- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setShards
Sets the range of shards theDefaultShardManager
should contain. This is useful if you want to split your shards between multiple JVMs or servers.This does not have any effect if the total shard count is set to
-1
(get recommended shards from discord).- Parameters:
minShardId
- The lowest shard id the DefaultShardManager should containmaxShardId
- The highest shard id the DefaultShardManager should contain- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If either minShardId is negative, maxShardId is lower than shardsTotal or minShardId is lower than or equal to maxShardId
-
setShards
Sets the range of shards theDefaultShardManager
should contain. This is useful if you want to split your shards between multiple JVMs or servers.This does not have any effect if the total shard count is set to
-1
(get recommended shards from discord).- Parameters:
shardIds
- The list of shard ids- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If either minShardId is negative, maxShardId is lower than shardsTotal or minShardId is lower than or equal to maxShardId
-
setShardsTotal
This will set the total amount of shards theDefaultShardManager
should use.If this is set to
-1
JDA will automatically retrieve the recommended amount of shards from discord (default behavior).- Parameters:
shardsTotal
- The number of overall shards or-1
if JDA should use the recommended amount from discord.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setToken
Sets the token that will be used by theShardManager
instance to log in whenbuild()
is called.To get a bot token:
- Go to your Discord Applications
- Create or select an already existing application
- Verify that it has already been turned into a Bot. If you see the "Create a Bot User" button, click it.
- Click the click to reveal link beside the Token label to show your Bot's
token
- Parameters:
token
- The token of the account that you would like to login with.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If the token is either null or empty
-
setUseShutdownNow
Whether theShardManager
should useJDA#shutdownNow()
instead ofJDA#shutdown()
to shutdown it's shards.
Default:false
- Parameters:
useShutdownNow
- Whether the ShardManager should use JDA#shutdown() or not- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- See Also:
-
setWebsocketFactory
Sets theWebSocketFactory
that will be used by JDA's websocket client. This can be used to set things such as connection timeout and proxy.- Parameters:
factory
- The newWebSocketFactory
to use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setChunkingFilter
TheChunkingFilter
to filter which guilds should use member chunking.Use
setMemberCachePolicy(MemberCachePolicy)
to configure which members to keep in cache from chunking.- Parameters:
filter
- The filter to apply- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
- See Also:
-
setDisabledIntents
@Nonnull public DefaultShardManagerBuilder setDisabledIntents(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Configures which events will be disabled. Bots which did not enable presence/member updates in the developer dashboard are required to disableGatewayIntent.GUILD_PRESENCES
andGatewayIntent.GUILD_MEMBERS
!It is not recommended to disable
GatewayIntent.GUILD_MEMBERS
when usingMemberCachePolicy.ALL
as the members cannot be removed from cache by a leave event without this intent.If you disable certain intents you also have to disable related
CacheFlags
. This can be achieved usingdisableCache(CacheFlag, CacheFlag...)
. The required intents for each flag are documented in theCacheFlag
enum.- Parameters:
intent
- The first intent to disableintents
- Any other intents to disable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If null is provided- Since:
- 4.2.0
- See Also:
-
setDisabledIntents
@Nonnull public DefaultShardManagerBuilder setDisabledIntents(@Nullable Collection<GatewayIntent> intents) Configures which events will be disabled. Bots which did not enable presence/member updates in the developer dashboard are required to disableGatewayIntent.GUILD_PRESENCES
andGatewayIntent.GUILD_MEMBERS
!It is not recommended to disable
GatewayIntent.GUILD_MEMBERS
when usingMemberCachePolicy.ALL
as the members cannot be removed from cache by a leave event without this intent.If you disable certain intents you also have to disable related
CacheFlags
. This can be achieved usingdisableCache(CacheFlag, CacheFlag...)
. The required intents for each flag are documented in theCacheFlag
enum.- Parameters:
intents
- The intents to disable, or null to disable all intents (default: none)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.0
- See Also:
-
disableIntents
@Nonnull public DefaultShardManagerBuilder disableIntents(@Nonnull Collection<GatewayIntent> intents) Disable the specifiedGatewayIntents
.
This will not enable any currently unset intents.If you disable certain intents you also have to disable related
CacheFlags
. This can be achieved usingdisableCache(CacheFlag, CacheFlag...)
. The required intents for each flag are documented in theCacheFlag
enum.- Parameters:
intents
- The intents to disable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
disableIntents
@Nonnull public DefaultShardManagerBuilder disableIntents(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Disable the specifiedGatewayIntents
.
This will not enable any currently unset intents.If you disable certain intents you also have to disable related
CacheFlags
. This can be achieved usingdisableCache(CacheFlag, CacheFlag...)
. The required intents for each flag are documented in theCacheFlag
enum.- Parameters:
intent
- The intent to disableintents
- Other intents to disable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
setEnabledIntents
@Nonnull public DefaultShardManagerBuilder setEnabledIntents(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Configures which events will be enabled. Bots which did not enable presence/member updates in the developer dashboard are required to disableGatewayIntent.GUILD_PRESENCES
andGatewayIntent.GUILD_MEMBERS
!It is not recommended to disable
GatewayIntent.GUILD_MEMBERS
when usingMemberCachePolicy.ALL
as the members cannot be removed from cache by a leave event without this intent.If you disable certain intents you also have to disable related
CacheFlags
. This can be achieved usingdisableCache(CacheFlag, CacheFlag...)
. The required intents for each flag are documented in theCacheFlag
enum.- Parameters:
intent
- The intent to enableintents
- Any other intents to enable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If null is provided- Since:
- 4.2.0
- See Also:
-
setEnabledIntents
@Nonnull public DefaultShardManagerBuilder setEnabledIntents(@Nullable Collection<GatewayIntent> intents) Configures which events will be enabled. Bots which did not enable presence/member updates in the developer dashboard are required to disableGatewayIntent.GUILD_PRESENCES
andGatewayIntent.GUILD_MEMBERS
!It is not recommended to disable
GatewayIntent.GUILD_MEMBERS
when usingMemberCachePolicy.ALL
as the members cannot be removed from cache by a leave event without this intent.If you disable certain intents you also have to disable related
CacheFlags
. This can be achieved usingdisableCache(CacheFlag, CacheFlag...)
. The required intents for each flag are documented in theCacheFlag
enum.- Parameters:
intents
- The intents to enable, or null to enable no intents (default: all)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.2.0
- See Also:
-
enableIntents
@Nonnull public DefaultShardManagerBuilder enableIntents(@Nonnull Collection<GatewayIntent> intents) Enable the specifiedGatewayIntents
.
This will not disable any currently set intents.- Parameters:
intents
- The intents to enable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
enableIntents
@Nonnull public DefaultShardManagerBuilder enableIntents(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents) Enable the specifiedGatewayIntents
.
This will not disable any currently set intents.- Parameters:
intent
- The intent to enableintents
- Other intents to enable- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If provided with null- See Also:
-
setLargeThreshold
Decides the total number of members at which a guild should start to use lazy loading.
This is limited to a number between 50 and 250 (inclusive). If thechunking filter
is set toChunkingFilter.ALL
this should be set to250
(default) to minimize the amount of guilds that need to request members.- Parameters:
threshold
- The threshold in[50, 250]
- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
-
setMaxBufferSize
The maximum size, in bytes, of the buffer used for decompressing discord payloads.
If the maximum buffer size is exceeded a new buffer will be allocated instead.
Setting this toInteger.MAX_VALUE
would imply the buffer will never be resized unless memory starvation is imminent.
Setting this to0
would imply the buffer would need to be allocated again for every payload (not recommended).Default:
2048
- Parameters:
bufferSize
- The maximum size the buffer should allow to retain- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
IllegalArgumentException
- If the provided buffer size is negative
-
build
Builds a newShardManager
instance and uses the provided token to start the login process.
The login process runs in a different thread, so while this will return immediately,ShardManager
has not finished loading, thus manyShardManager
methods have the chance to return incorrect information.
The main use of this method is to start the JDA connect process and do other things in parallel while startup is being performed like database connection or local resource loading.Note that this method is async and as such will not block until all shards are started.
- Returns:
- A
ShardManager
instance that has started the login process. It is unknown as to whether or not loading has finished when this returns. - Throws:
InvalidTokenException
- If the provided token is invalid.IllegalArgumentException
- If the provided token is empty or null. Or the provided intents/cache configuration is not possible.ErrorResponseException
- If some other HTTP error occurred.
-
build
Builds a newShardManager
instance. If the login parameter is true, then it will start the login process.
The login process runs in a different thread, so while this will return immediately,ShardManager
has not finished loading, thus manyShardManager
methods have the chance to return incorrect information.
The main use of this method is to start the JDA connect process and do other things in parallel while startup is being performed like database connection or local resource loading.Note that this method is async and as such will not block until all shards are started.
- Parameters:
login
- Whether the login process will be started. If this is false, then you will need to manually callShardManager.login()
to start it.- Returns:
- A
ShardManager
instance. Iflogin
is set to true, then the instance will have started the login process. It is unknown as to whether or not loading has finished when this returns. - Throws:
InvalidTokenException
- If the provided token is invalid andlogin
is trueIllegalArgumentException
- If the provided token is empty or null. Or the provided intents/cache configuration is not possible.
-