Class DefaultShardManagerBuilder
- java.lang.Object
-
- net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder
-
public class DefaultShardManagerBuilder extends java.lang.Object
Used to create new instances of JDA's defaultShardManager
implementation.A single DefaultShardManagerBuilder can be reused multiple times. Each call to
build()
creates a newShardManager
instance using the same information.- Since:
- 3.4.0
- Author:
- Aljoscha Grebe
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DefaultShardManagerBuilder
addEventListenerProvider(java.util.function.IntFunction<java.lang.Object> listenerProvider)
Adds the provided listener provider to the list of listener providers that will be used to create listeners.DefaultShardManagerBuilder
addEventListenerProviders(java.util.Collection<java.util.function.IntFunction<java.lang.Object>> listenerProviders)
Adds the provided listener providers to the list of listener providers that will be used to create listeners.DefaultShardManagerBuilder
addEventListeners(java.lang.Object... listeners)
Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManager
object.DefaultShardManagerBuilder
addEventListeners(java.util.Collection<java.lang.Object> listeners)
Adds all provided listeners to the list of listeners that will be used to populate theDefaultShardManager
object.ShardManager
build()
Builds a newShardManager
instance and uses the provided token to start the login process.ShardManager
build(boolean login)
Builds a newShardManager
instance.static DefaultShardManagerBuilder
create(java.lang.String token, java.util.Collection<GatewayIntent> intents)
Creates a DefaultShardManagerBuilder with the predefined token.static DefaultShardManagerBuilder
create(java.lang.String token, GatewayIntent intent, GatewayIntent... intents)
Creates a DefaultShardManagerBuilder with the predefined token.static DefaultShardManagerBuilder
create(java.util.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(java.lang.String token)
Creates a DefaultShardManagerBuilder with recommended default settings.static DefaultShardManagerBuilder
createDefault(java.lang.String token, java.util.Collection<GatewayIntent> intents)
Creates a DefaultShardManagerBuilder with recommended default settings.static DefaultShardManagerBuilder
createDefault(java.lang.String token, GatewayIntent intent, GatewayIntent... intents)
Creates a DefaultShardManagerBuilder with recommended default settings.static DefaultShardManagerBuilder
createLight(java.lang.String token)
Creates a DefaultShardManagerBuilder with low memory profile settings.static DefaultShardManagerBuilder
createLight(java.lang.String token, java.util.Collection<GatewayIntent> intents)
Creates a DefaultShardManagerBuilder with low memory profile settings.static DefaultShardManagerBuilder
createLight(java.lang.String token, GatewayIntent intent, GatewayIntent... intents)
Creates a DefaultShardManagerBuilder with low memory profile settings.DefaultShardManagerBuilder
disableCache(java.util.Collection<CacheFlag> flags)
Disable specific cache flags.DefaultShardManagerBuilder
disableCache(CacheFlag flag, CacheFlag... flags)
Disable specific cache flags.DefaultShardManagerBuilder
disableIntents(java.util.Collection<GatewayIntent> intents)
Disable the specifiedGatewayIntents
.DefaultShardManagerBuilder
disableIntents(GatewayIntent intent, GatewayIntent... intents)
Disable the specifiedGatewayIntents
.DefaultShardManagerBuilder
enableCache(java.util.Collection<CacheFlag> flags)
Enable specific cache flags.DefaultShardManagerBuilder
enableCache(CacheFlag flag, CacheFlag... flags)
Enable specific cache flags.DefaultShardManagerBuilder
enableIntents(java.util.Collection<GatewayIntent> intents)
Enable the specifiedGatewayIntents
.DefaultShardManagerBuilder
enableIntents(GatewayIntent intent, GatewayIntent... intents)
Enable the specifiedGatewayIntents
.DefaultShardManagerBuilder
removeEventListenerProvider(java.util.function.IntFunction<java.lang.Object> listenerProvider)
Removes the provided listener provider from the list of listener providers.DefaultShardManagerBuilder
removeEventListenerProviders(java.util.Collection<java.util.function.IntFunction<java.lang.Object>> listenerProviders)
Removes all provided listener providers from the list of listener providers.DefaultShardManagerBuilder
removeEventListeners(java.lang.Object... listeners)
Removes all provided listeners from the list of listeners.DefaultShardManagerBuilder
removeEventListeners(java.util.Collection<java.lang.Object> listeners)
Removes all provided listeners from the list of listeners.DefaultShardManagerBuilder
setActivity(Activity activity)
Sets theActivity
for our session.DefaultShardManagerBuilder
setActivityProvider(java.util.function.IntFunction<? extends Activity> activityProvider)
Sets theActivity
for our session.DefaultShardManagerBuilder
setAudioPool(java.util.concurrent.ScheduledExecutorService pool)
Sets theScheduledExecutorService
used by the audio WebSocket connection.DefaultShardManagerBuilder
setAudioPool(java.util.concurrent.ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorService
used by the audio WebSocket connection.DefaultShardManagerBuilder
setAudioPoolProvider(ThreadPoolProvider<? extends java.util.concurrent.ScheduledExecutorService> provider)
Sets theScheduledExecutorService
used by the audio WebSocket connection.DefaultShardManagerBuilder
setAudioSendFactory(IAudioSendFactory factory)
Changes the factory used to createIAudioSendSystem
objects which handle the sending loop for audio packets.DefaultShardManagerBuilder
setAutoReconnect(boolean autoReconnect)
Sets whether or not JDA should try to reconnect if a connection-error is encountered.DefaultShardManagerBuilder
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.DefaultShardManagerBuilder
setCallbackPool(java.util.concurrent.ExecutorService executor)
Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.DefaultShardManagerBuilder
setCallbackPool(java.util.concurrent.ExecutorService executor, boolean automaticShutdown)
Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.DefaultShardManagerBuilder
setCallbackPoolProvider(ThreadPoolProvider<? extends java.util.concurrent.ExecutorService> provider)
Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.DefaultShardManagerBuilder
setChunkingFilter(ChunkingFilter filter)
TheChunkingFilter
to filter which guilds should use member chunking.DefaultShardManagerBuilder
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.DefaultShardManagerBuilder
setContextEnabled(boolean enable)
Whether JDA should use a synchronized MDC context for all of its controlled threads.DefaultShardManagerBuilder
setContextMap(java.util.function.IntFunction<? extends java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String>> provider)
Sets theMDC
mappings provider to use in JDA.DefaultShardManagerBuilder
setDisabledCacheFlags(java.util.EnumSet<CacheFlag> flags)
Deprecated.We add CacheFlags to the enum over time which will be disabled when using this method.DefaultShardManagerBuilder
setDisabledIntents(java.util.Collection<GatewayIntent> intents)
Configures which events will be disabled.DefaultShardManagerBuilder
setDisabledIntents(GatewayIntent intent, GatewayIntent... intents)
Configures which events will be disabled.DefaultShardManagerBuilder
setEnabledCacheFlags(java.util.EnumSet<CacheFlag> flags)
Deprecated.We add CacheFlags to the enum over time which will be disabled when using this method.DefaultShardManagerBuilder
setEnabledIntents(java.util.Collection<GatewayIntent> intents)
Configures which events will be enabled.DefaultShardManagerBuilder
setEnabledIntents(GatewayIntent intent, GatewayIntent... intents)
Configures which events will be enabled.DefaultShardManagerBuilder
setEnableShutdownHook(boolean enable)
Enables/Disables the use of a Shutdown hook to clean up the ShardManager and it's JDA instances.DefaultShardManagerBuilder
setEventManager(IEventManager manager)
Deprecated.UsesetEventManagerProvider(IntFunction)
insteadDefaultShardManagerBuilder
setEventManagerProvider(java.util.function.IntFunction<? extends IEventManager> eventManagerProvider)
Sets a provider to change the internally used EventManager.DefaultShardManagerBuilder
setEventPool(java.util.concurrent.ExecutorService executor)
Sets theExecutorService
that should be used by the event proxy to schedule events.DefaultShardManagerBuilder
setEventPool(java.util.concurrent.ExecutorService executor, boolean automaticShutdown)
Sets theExecutorService
that should be used by the event proxy to schedule events.DefaultShardManagerBuilder
setEventPoolProvider(ThreadPoolProvider<? extends java.util.concurrent.ExecutorService> provider)
Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.DefaultShardManagerBuilder
setGatewayEncoding(GatewayEncoding encoding)
Choose whichGatewayEncoding
JDA should use.DefaultShardManagerBuilder
setGatewayPool(java.util.concurrent.ScheduledExecutorService pool)
Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.DefaultShardManagerBuilder
setGatewayPool(java.util.concurrent.ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.DefaultShardManagerBuilder
setGatewayPoolProvider(ThreadPoolProvider<? extends java.util.concurrent.ScheduledExecutorService> provider)
Sets theScheduledExecutorService
that should be used for the JDA main WebSocket workers.DefaultShardManagerBuilder
setGuildSubscriptionsEnabled(boolean enabled)
Deprecated.This is now superceded bysetDisabledIntents(Collection)
andsetMemberCachePolicy(MemberCachePolicy)
.DefaultShardManagerBuilder
setHttpClient(OkHttpClient client)
Sets theOkHttpClient
that will be used by JDAs requester.DefaultShardManagerBuilder
setHttpClientBuilder(OkHttpClient.Builder builder)
Sets theBuilder
that will be used by JDA's requester.DefaultShardManagerBuilder
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)
.DefaultShardManagerBuilder
setIdleProvider(java.util.function.IntFunction<java.lang.Boolean> idleProvider)
Sets whether or not we should mark our sessions as afk
This value can be changed at any time usingDefaultShardManager#setIdleProvider(boolean)
.DefaultShardManagerBuilder
setLargeThreshold(int threshold)
Decides the total number of members at which a guild should start to use lazy loading.DefaultShardManagerBuilder
setMaxBufferSize(int bufferSize)
The maximum size, in bytes, of the buffer used for decompressing discord payloads.DefaultShardManagerBuilder
setMaxReconnectDelay(int maxReconnectDelay)
Sets the maximum amount of time that JDA will back off to wait when attempting to reconnect the MainWebsocket.DefaultShardManagerBuilder
setMemberCachePolicy(MemberCachePolicy policy)
Configure the member caching policy.DefaultShardManagerBuilder
setRateLimitPool(java.util.concurrent.ScheduledExecutorService pool)
Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler.DefaultShardManagerBuilder
setRateLimitPool(java.util.concurrent.ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler.DefaultShardManagerBuilder
setRateLimitPoolProvider(ThreadPoolProvider<? extends java.util.concurrent.ScheduledExecutorService> provider)
Sets theScheduledExecutorService
provider that should be used in the JDA rate-limit handler.DefaultShardManagerBuilder
setRawEventsEnabled(boolean enable)
Whether JDA should fireRawGatewayEvent
for every discord event.DefaultShardManagerBuilder
setRelativeRateLimit(boolean enable)
Whether the rate-limit should be relative to the current time plus latency.DefaultShardManagerBuilder
setRequestTimeoutRetry(boolean retryOnTimeout)
Whether the Requester should retry when aSocketTimeoutException
occurs.DefaultShardManagerBuilder
setSessionController(SessionController controller)
Sets theSessionController
for the resulting ShardManager instance.DefaultShardManagerBuilder
setShards(int... shardIds)
Sets the list of shards theDefaultShardManager
should contain.DefaultShardManagerBuilder
setShards(int minShardId, int maxShardId)
Sets the range of shards theDefaultShardManager
should contain.DefaultShardManagerBuilder
setShards(java.util.Collection<java.lang.Integer> shardIds)
Sets the range of shards theDefaultShardManager
should contain.DefaultShardManagerBuilder
setShardsTotal(int shardsTotal)
This will set the total amount of shards theDefaultShardManager
should use.DefaultShardManagerBuilder
setStatus(OnlineStatus status)
Sets theOnlineStatus
our connection will display.DefaultShardManagerBuilder
setStatusProvider(java.util.function.IntFunction<OnlineStatus> statusProvider)
Sets theOnlineStatus
our connection will display.DefaultShardManagerBuilder
setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Sets theThreadFactory
that will be used by the internal executor of the ShardManager.DefaultShardManagerBuilder
setToken(java.lang.String token)
Sets the token that will be used by theShardManager
instance to log in whenbuild()
is called.DefaultShardManagerBuilder
setUseShutdownNow(boolean useShutdownNow)
Whether theShardManager
should useJDA#shutdownNow()
instead ofJDA#shutdown()
to shutdown it's shards.DefaultShardManagerBuilder
setVoiceDispatchInterceptor(VoiceDispatchInterceptor interceptor)
Configures a custom voice dispatch handler which handles audio connections.DefaultShardManagerBuilder
setWebsocketFactory(WebSocketFactory factory)
Sets theWebSocketFactory
that will be used by JDA's websocket client.
-
-
-
Method Detail
-
createDefault
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createDefault(@Nullable java.lang.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:
disableIntents(GatewayIntent, GatewayIntent...)
,enableIntents(GatewayIntent, GatewayIntent...)
-
createDefault
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createDefault(@Nullable java.lang.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:
java.lang.IllegalArgumentException
- If provided with null intents
-
createDefault
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createDefault(@Nullable java.lang.String token, @Nonnull java.util.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:
java.lang.IllegalArgumentException
- If provided with null intents
-
createLight
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createLight(@Nullable java.lang.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:
disableIntents(GatewayIntent, GatewayIntent...)
,enableIntents(GatewayIntent, GatewayIntent...)
-
createLight
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder createLight(@Nullable java.lang.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 java.lang.String token, @Nonnull java.util.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:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
create
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder create(@Nonnull java.util.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:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
create
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder create(@Nullable java.lang.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:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
create
@Nonnull @CheckReturnValue public static DefaultShardManagerBuilder create(@Nullable java.lang.String token, @Nonnull java.util.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:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
setGatewayEncoding
@Nonnull public DefaultShardManagerBuilder setGatewayEncoding(@Nonnull GatewayEncoding encoding)
Choose whichGatewayEncoding
JDA should use.- Parameters:
encoding
- TheGatewayEncoding
(default: JSON)- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If null is provided- Since:
- 4.2.1
-
setRawEventsEnabled
@Nonnull public DefaultShardManagerBuilder setRawEventsEnabled(boolean enable)
- Parameters:
enable
- True, if JDA should fireRawGatewayEvent
.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
-
setRelativeRateLimit
@Nonnull public DefaultShardManagerBuilder setRelativeRateLimit(boolean enable)
Whether the rate-limit should be relative to the current time plus latency.
By default we use theX-RateLimit-Rest-After
header to determine when a rate-limit is no longer imminent. This has the disadvantage that it might wait longer than needed due to the latency which is ignored by the reset-after relative delay.When disabled, we will use the
X-RateLimit-Reset
absolute timestamp instead which accounts for latency but requires a properly NTP synchronized clock to be present. If your system does have this feature you might gain a little quicker rate-limit handling than the default allows.Default: true
- Parameters:
enable
- True, if the relativeX-RateLimit-Reset-After
header should be used.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.1.0
-
setEnabledCacheFlags
@Nonnull @Deprecated @ForRemoval(deadline="5.0.0") @ReplaceWith("enableCache(flags) and disableCache(flags)") @DeprecatedSince("4.2.0") public DefaultShardManagerBuilder setEnabledCacheFlags(@Nullable java.util.EnumSet<CacheFlag> flags)
Deprecated.We add CacheFlags to the enum over time which will be disabled when using this method. This introduces breaking changes due to the way the setter works. You should useenableCache(Collection)
anddisableCache(Collection)
instead, to disable and enable cache flags without side-effects that may break in future versions.Flags used to enable parts of the JDA cache to reduce the runtime memory footprint.
It is highly recommended to usesetDisabledCacheFlags(EnumSet)
instead for backwards compatibility. We might add more flags in the future which you then effectively disable when updating and not changing your setting here.- Parameters:
flags
- EnumSet containing the flags for cache services that should be enabled- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
enableCache
@Nonnull public DefaultShardManagerBuilder enableCache(@Nonnull java.util.Collection<CacheFlag> flags)
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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableCache(CacheFlag, CacheFlag...)
,disableCache(Collection)
-
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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableCache(Collection)
,disableCache(CacheFlag, CacheFlag...)
-
setDisabledCacheFlags
@Nonnull @Deprecated @ForRemoval(deadline="5.0.0") @ReplaceWith("enableCache(flags) and disableCache(flags)") @DeprecatedSince("4.2.0") public DefaultShardManagerBuilder setDisabledCacheFlags(@Nullable java.util.EnumSet<CacheFlag> flags)
Deprecated.We add CacheFlags to the enum over time which will be disabled when using this method. This introduces breaking changes due to the way the setter works. You should useenableCache(Collection)
anddisableCache(Collection)
instead, to disable and enable cache flags without side-effects that may break in future versions.Flags used to disable parts of the JDA cache to reduce the runtime memory footprint.
Shortcut forsetEnabledCacheFlags(EnumSet.complementOf(flags))
- Parameters:
flags
- EnumSet containing the flags for cache services that should be disabled- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
disableCache
@Nonnull public DefaultShardManagerBuilder disableCache(@Nonnull java.util.Collection<CacheFlag> flags)
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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
disableCache(CacheFlag, CacheFlag...)
,enableCache(Collection)
-
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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
disableCache(Collection)
,enableCache(CacheFlag, CacheFlag...)
-
setMemberCachePolicy
@Nonnull public DefaultShardManagerBuilder setMemberCachePolicy(@Nullable MemberCachePolicy policy)
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:
MemberCachePolicy
,setEnabledIntents(Collection)
-
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:
SessionControllerAdapter
-
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:
VoiceDispatchInterceptor
-
setContextMap
@Nonnull public DefaultShardManagerBuilder setContextMap(@Nullable java.util.function.IntFunction<? extends java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.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:
- MDC Javadoc
-
setContextEnabled
@Nonnull public DefaultShardManagerBuilder setContextEnabled(boolean enable)
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:
- MDC Javadoc,
setContextMap(java.util.function.IntFunction)
-
setCompression
@Nonnull public DefaultShardManagerBuilder setCompression(@Nonnull 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. 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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
- Official Discord Documentation - Transport Compression
-
addEventListeners
@Nonnull public DefaultShardManagerBuilder addEventListeners(@Nonnull java.lang.Object... listeners)
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:
JDA.addEventListeners(Object...)
-
addEventListeners
@Nonnull public DefaultShardManagerBuilder addEventListeners(@Nonnull java.util.Collection<java.lang.Object> listeners)
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:
JDA.addEventListeners(Object...)
-
removeEventListeners
@Nonnull public DefaultShardManagerBuilder removeEventListeners(@Nonnull java.lang.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:
JDA.removeEventListeners(Object...)
-
removeEventListeners
@Nonnull public DefaultShardManagerBuilder removeEventListeners(@Nonnull java.util.Collection<java.lang.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:
JDA.removeEventListeners(Object...)
-
addEventListenerProvider
@Nonnull public DefaultShardManagerBuilder addEventListenerProvider(@Nonnull java.util.function.IntFunction<java.lang.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 java.util.Collection<java.util.function.IntFunction<java.lang.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 java.util.function.IntFunction<java.lang.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 java.util.Collection<java.util.function.IntFunction<java.lang.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
@Nonnull public DefaultShardManagerBuilder setAudioSendFactory(@Nullable IAudioSendFactory factory)
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
@Nonnull public DefaultShardManagerBuilder setAutoReconnect(boolean autoReconnect)
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
@Nonnull public DefaultShardManagerBuilder 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. 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
@Nonnull public DefaultShardManagerBuilder setEnableShutdownHook(boolean enable)
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.
-
setEventManager
@Nonnull @Deprecated @ForRemoval(deadline="5.0.0") @DeprecatedSince("3.8.1") @ReplaceWith("setEventManagerProvider((id) -> manager)") public DefaultShardManagerBuilder setEventManager(@Nonnull IEventManager manager)
Deprecated.UsesetEventManagerProvider(IntFunction)
insteadChanges 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:
manager
- The newIEventManager
to use.- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setEventManagerProvider
@Nonnull public DefaultShardManagerBuilder setEventManagerProvider(@Nonnull java.util.function.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
@Nonnull public DefaultShardManagerBuilder setActivity(@Nullable Activity activity)
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:
Presence.setActivity(net.dv8tion.jda.api.entities.Activity)
-
setActivityProvider
@Nonnull public DefaultShardManagerBuilder setActivityProvider(@Nullable java.util.function.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:
Presence.setActivity(net.dv8tion.jda.api.entities.Activity)
-
setIdle
@Nonnull public DefaultShardManagerBuilder 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)
.- 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:
Presence.setIdle(boolean)
-
setIdleProvider
@Nonnull public DefaultShardManagerBuilder setIdleProvider(@Nullable java.util.function.IntFunction<java.lang.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:
Presence.setIdle(boolean)
-
setStatus
@Nonnull public DefaultShardManagerBuilder setStatus(@Nullable OnlineStatus status)
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:
java.lang.IllegalArgumentException
- if the provided OnlineStatus is null orUNKNOWN
- See Also:
Presence.setStatusProvider(OnlineStatus)
-
setStatusProvider
@Nonnull public DefaultShardManagerBuilder setStatusProvider(@Nullable java.util.function.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:
java.lang.IllegalArgumentException
- if the provided OnlineStatus is null orUNKNOWN
- See Also:
Presence.setStatusProvider(OnlineStatus)
-
setThreadFactory
@Nonnull public DefaultShardManagerBuilder setThreadFactory(@Nullable java.util.concurrent.ThreadFactory threadFactory)
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 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
@Nonnull public DefaultShardManagerBuilder setHttpClient(@Nullable OkHttpClient client)
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.
-
setRateLimitPool
@Nonnull public DefaultShardManagerBuilder setRateLimitPool(@Nullable java.util.concurrent.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 fromsetRateLimitPoolProvider(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.Default:
ScheduledThreadPoolExecutor
with 5 threads (per shard).- Parameters:
pool
- The thread-pool to use for rate-limit handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setRateLimitPool
@Nonnull public DefaultShardManagerBuilder setRateLimitPool(@Nullable java.util.concurrent.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 fromsetRateLimitPoolProvider(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.Default:
ScheduledThreadPoolExecutor
with 5 threads (per shard).- 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.
-
setRateLimitPoolProvider
@Nonnull public DefaultShardManagerBuilder setRateLimitPoolProvider(@Nullable ThreadPoolProvider<? extends java.util.concurrent.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.Default:
ScheduledThreadPoolExecutor
with 5 threads (per shard).- Parameters:
provider
- The thread-pool provider to use for rate-limit handling- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPool
@Nonnull public DefaultShardManagerBuilder setGatewayPool(@Nullable java.util.concurrent.ScheduledExecutorService pool)
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:
ScheduledThreadPoolExecutor
with 1 thread (per shard)- Parameters:
pool
- The thread-pool to use for main WebSocket workers- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setGatewayPool
@Nonnull public DefaultShardManagerBuilder setGatewayPool(@Nullable java.util.concurrent.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:
ScheduledThreadPoolExecutor
with 1 thread (per shard)- 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 java.util.concurrent.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:
ScheduledThreadPoolExecutor
with 1 thread (per shard)- Parameters:
provider
- The thread-pool provider to use for main WebSocket workers- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
-
setCallbackPool
@Nonnull public DefaultShardManagerBuilder setCallbackPool(@Nullable java.util.concurrent.ExecutorService executor)
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 java.util.concurrent.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 java.util.concurrent.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
@Nonnull public DefaultShardManagerBuilder setEventPool(@Nullable java.util.concurrent.ExecutorService executor)
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)
.- 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 java.util.concurrent.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.- 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 java.util.concurrent.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.
- Since:
- 4.2.0
-
setAudioPool
@Nonnull public DefaultShardManagerBuilder setAudioPool(@Nullable java.util.concurrent.ScheduledExecutorService pool)
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 java.util.concurrent.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 java.util.concurrent.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
@Nonnull public DefaultShardManagerBuilder setMaxReconnectDelay(int maxReconnectDelay)
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:
java.lang.IllegalArgumentException
- Thrown if the providedmaxReconnectDelay
is less than 32.
-
setRequestTimeoutRetry
@Nonnull public DefaultShardManagerBuilder setRequestTimeoutRetry(boolean retryOnTimeout)
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
@Nonnull public DefaultShardManagerBuilder setShards(int... shardIds)
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
@Nonnull public DefaultShardManagerBuilder setShards(int minShardId, int maxShardId)
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:
java.lang.IllegalArgumentException
- If either minShardId is negative, maxShardId is lower than shardsTotal or minShardId is lower than or equal to maxShardId
-
setShards
@Nonnull public DefaultShardManagerBuilder setShards(@Nonnull java.util.Collection<java.lang.Integer> shardIds)
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:
java.lang.IllegalArgumentException
- If either minShardId is negative, maxShardId is lower than shardsTotal or minShardId is lower than or equal to maxShardId
-
setShardsTotal
@Nonnull public DefaultShardManagerBuilder setShardsTotal(int shardsTotal)
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:
setShards(int, int)
-
setToken
@Nonnull public DefaultShardManagerBuilder setToken(@Nonnull java.lang.String token)
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:
java.lang.IllegalArgumentException
- If the token is either null or empty
-
setUseShutdownNow
@Nonnull public DefaultShardManagerBuilder setUseShutdownNow(boolean useShutdownNow)
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:
JDA.shutdown()
,JDA.shutdownNow()
-
setWebsocketFactory
@Nonnull public DefaultShardManagerBuilder setWebsocketFactory(@Nullable WebSocketFactory factory)
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
@Nonnull public DefaultShardManagerBuilder setChunkingFilter(@Nullable ChunkingFilter filter)
TheChunkingFilter
to filter which guilds should use member chunking.
By default this usesChunkingFilter.ALL
.If a guild is configured for chunking the
setMemberCachePolicy(MemberCachePolicy)
will be ignored.- Parameters:
filter
- The filter to apply- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.0.0
- See Also:
ChunkingFilter.NONE
,ChunkingFilter.include(long...)
,ChunkingFilter.exclude(long...)
-
setGuildSubscriptionsEnabled
@Nonnull @Deprecated @ForRemoval(deadline="5.0.0") @ReplaceWith("setDisabledIntents(...).setMemberCachePolicy(...)") @DeprecatedSince("4.2.0") public DefaultShardManagerBuilder setGuildSubscriptionsEnabled(boolean enabled)
Deprecated.This is now superceded bysetDisabledIntents(Collection)
andsetMemberCachePolicy(MemberCachePolicy)
. To get identical behavior you can dosetMemberCachePolicy(VOICE).setDisabledIntents(GatewayIntent.GUILD_PRESENCES, GatewayIntent.GUILD_MESSAGE_TYPING, GatewayIntent.GUILD_MEMBERS)
Enable typing and presence update events.
These events cover the majority of traffic happening on the gateway and thus cause a lot of bandwidth usage. Disabling these events means the cache for users might become outdated since user properties are only updated by presence updates.
Default: trueNotice
This disables the majority of member cache and related events. If anything in your project relies on member state you should keep this enabled.- Parameters:
enabled
- True, if guild subscriptions should be enabled- Returns:
- The DefaultShardManagerBuilder instance. Useful for chaining.
- Since:
- 4.1.0
-
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:
java.lang.IllegalArgumentException
- If null is provided- Since:
- 4.2.0
- See Also:
setMemberCachePolicy(MemberCachePolicy)
-
setDisabledIntents
@Nonnull public DefaultShardManagerBuilder setDisabledIntents(@Nullable java.util.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:
setMemberCachePolicy(MemberCachePolicy)
-
disableIntents
@Nonnull public DefaultShardManagerBuilder disableIntents(@Nonnull java.util.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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableIntents(Collection)
-
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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableIntents(GatewayIntent, GatewayIntent...)
-
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:
java.lang.IllegalArgumentException
- If null is provided- Since:
- 4.2.0
- See Also:
setMemberCachePolicy(MemberCachePolicy)
-
setEnabledIntents
@Nonnull public DefaultShardManagerBuilder setEnabledIntents(@Nullable java.util.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:
setMemberCachePolicy(MemberCachePolicy)
-
enableIntents
@Nonnull public DefaultShardManagerBuilder enableIntents(@Nonnull java.util.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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
disableIntents(Collection)
-
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:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableIntents(GatewayIntent, GatewayIntent...)
-
setLargeThreshold
@Nonnull public DefaultShardManagerBuilder setLargeThreshold(int threshold)
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
@Nonnull public DefaultShardManagerBuilder setMaxBufferSize(int bufferSize)
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:
java.lang.IllegalArgumentException
- If the provided buffer size is negative
-
build
@Nonnull public ShardManager build() throws javax.security.auth.login.LoginException, java.lang.IllegalArgumentException
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:
javax.security.auth.login.LoginException
- If the provided token is invalid.java.lang.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
@Nonnull public ShardManager build(boolean login) throws javax.security.auth.login.LoginException, java.lang.IllegalArgumentException
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:
javax.security.auth.login.LoginException
- If the provided token is invalid andlogin
is truejava.lang.IllegalArgumentException
- If the provided token is empty or null. Or the provided intents/cache configuration is not possible.
-
-