Class JDABuilder
- java.lang.Object
-
- net.dv8tion.jda.api.JDABuilder
-
public class JDABuilder extends java.lang.Object
Used to create newJDA
instances. This is also useful for making sure all of yourEventListeners
are registered beforeJDA
attempts to log in.A single JDABuilder can be reused multiple times. Each call to
build()
creates a newJDA
instance using the same information. This means that you can have listeners easily registered to multipleJDA
instances.
-
-
Field Summary
Fields Modifier and Type Field Description static int
GUILD_SUBSCRIPTIONS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JDABuilder
addEventListeners(java.lang.Object... listeners)
Adds all provided listeners to the list of listeners that will be used to populate theJDA
object.JDA
build()
Builds a newJDA
instance and uses the provided token to start the login process.static JDABuilder
create(java.lang.String token, java.util.Collection<GatewayIntent> intents)
Creates a JDABuilder with the predefined token.static JDABuilder
create(java.lang.String token, GatewayIntent intent, GatewayIntent... intents)
Creates a JDABuilder with the predefined token.static JDABuilder
create(java.util.Collection<GatewayIntent> intents)
Creates a completely empty JDABuilder with the predefined intents.static JDABuilder
create(GatewayIntent intent, GatewayIntent... intents)
Creates a completely empty JDABuilder with the predefined intents.static JDABuilder
createDefault(java.lang.String token)
Creates a JDABuilder with recommended default settings.static JDABuilder
createDefault(java.lang.String token, java.util.Collection<GatewayIntent> intents)
Creates a JDABuilder with recommended default settings.static JDABuilder
createDefault(java.lang.String token, GatewayIntent intent, GatewayIntent... intents)
Creates a JDABuilder with recommended default settings.static JDABuilder
createLight(java.lang.String token)
Creates a JDABuilder with low memory profile settings.static JDABuilder
createLight(java.lang.String token, java.util.Collection<GatewayIntent> intents)
Creates a JDABuilder with low memory profile settings.static JDABuilder
createLight(java.lang.String token, GatewayIntent intent, GatewayIntent... intents)
Creates a JDABuilder with low memory profile settings.JDABuilder
disableCache(java.util.Collection<CacheFlag> flags)
Disable specific cache flags.JDABuilder
disableCache(CacheFlag flag, CacheFlag... flags)
Disable specific cache flags.JDABuilder
disableIntents(java.util.Collection<GatewayIntent> intents)
Disable the specifiedGatewayIntents
.JDABuilder
disableIntents(GatewayIntent intent, GatewayIntent... intents)
Disable the specifiedGatewayIntents
.JDABuilder
enableCache(java.util.Collection<CacheFlag> flags)
Enable specific cache flags.JDABuilder
enableCache(CacheFlag flag, CacheFlag... flags)
Enable specific cache flags.JDABuilder
enableIntents(java.util.Collection<GatewayIntent> intents)
Enable the specifiedGatewayIntents
.JDABuilder
enableIntents(GatewayIntent intent, GatewayIntent... intents)
Enable the specifiedGatewayIntents
.JDABuilder
removeEventListeners(java.lang.Object... listeners)
Removes all provided listeners from the list of listeners.JDABuilder
setActivity(Activity activity)
Sets theActivity
for our session.JDABuilder
setAudioPool(java.util.concurrent.ScheduledExecutorService pool)
Sets theScheduledExecutorService
used by the audio WebSocket connection.JDABuilder
setAudioPool(java.util.concurrent.ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorService
used by the audio WebSocket connection.JDABuilder
setAudioSendFactory(IAudioSendFactory factory)
Changes the factory used to createIAudioSendSystem
objects which handle the sending loop for audio packets.JDABuilder
setAutoReconnect(boolean autoReconnect)
Sets whether or not JDA should try to reconnect if a connection-error is encountered.JDABuilder
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.JDABuilder
setCallbackPool(java.util.concurrent.ExecutorService executor)
Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.JDABuilder
setCallbackPool(java.util.concurrent.ExecutorService executor, boolean automaticShutdown)
Sets theExecutorService
that should be used in the JDA callback handler which mostly consists ofRestAction
callbacks.JDABuilder
setChunkingFilter(ChunkingFilter filter)
TheChunkingFilter
to filter which guilds should use member chunking.JDABuilder
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.JDABuilder
setContextEnabled(boolean enable)
Whether JDA should use a synchronized MDC context for all of its controlled threads.JDABuilder
setContextMap(java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> map)
Sets theMDC
mappings to use in JDA.JDABuilder
setDisabledCacheFlags(java.util.EnumSet<CacheFlag> flags)
Deprecated.We add CacheFlags to the enum over time which will be disabled when using this method.JDABuilder
setDisabledIntents(java.util.Collection<GatewayIntent> intents)
Configures which events will be disabled.JDABuilder
setDisabledIntents(GatewayIntent intent, GatewayIntent... intents)
Configures which events will be disabled.JDABuilder
setEnabledCacheFlags(java.util.EnumSet<CacheFlag> flags)
Deprecated.We add CacheFlags to the enum over time which will be disabled when using this method.JDABuilder
setEnabledIntents(java.util.Collection<GatewayIntent> intents)
Configures which events will be enabled.JDABuilder
setEnabledIntents(GatewayIntent intent, GatewayIntent... intents)
Configures which events will be enabled.JDABuilder
setEnableShutdownHook(boolean enable)
Enables/Disables the use of a Shutdown hook to clean up JDA.JDABuilder
setEventManager(IEventManager manager)
Changes the internally used EventManager.JDABuilder
setEventPool(java.util.concurrent.ExecutorService executor)
Sets theExecutorService
that should be used by the event proxy to schedule events.JDABuilder
setEventPool(java.util.concurrent.ExecutorService executor, boolean automaticShutdown)
Sets theExecutorService
that should be used by the event proxy to schedule events.JDABuilder
setGatewayEncoding(GatewayEncoding encoding)
Choose whichGatewayEncoding
JDA should use.JDABuilder
setGatewayPool(java.util.concurrent.ScheduledExecutorService pool)
Sets theScheduledExecutorService
used by the main WebSocket connection for workers.JDABuilder
setGatewayPool(java.util.concurrent.ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorService
used by the main WebSocket connection for workers.JDABuilder
setGuildSubscriptionsEnabled(boolean enabled)
Deprecated.This is now superseded bysetDisabledIntents(Collection)
andsetMemberCachePolicy(MemberCachePolicy)
.JDABuilder
setHttpClient(OkHttpClient client)
Sets theOkHttpClient
that will be used by JDAs requester.JDABuilder
setHttpClientBuilder(OkHttpClient.Builder builder)
Sets theBuilder
that will be used by JDAs requester.JDABuilder
setIdle(boolean idle)
Sets whether or not we should mark our session as afk
This value can be changed at any time in thePresence
from a JDA instance.JDABuilder
setLargeThreshold(int threshold)
Decides the total number of members at which a guild should start to use lazy loading.JDABuilder
setMaxBufferSize(int bufferSize)
The maximum size, in bytes, of the buffer used for decompressing discord payloads.JDABuilder
setMaxReconnectDelay(int maxReconnectDelay)
Sets the maximum amount of time that JDA will back off to wait when attempting to reconnect the MainWebsocket.JDABuilder
setMemberCachePolicy(MemberCachePolicy policy)
Configure the member caching policy.JDABuilder
setRateLimitPool(java.util.concurrent.ScheduledExecutorService pool)
Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler.JDABuilder
setRateLimitPool(java.util.concurrent.ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorService
that should be used in the JDA rate-limit handler.JDABuilder
setRawEventsEnabled(boolean enable)
Whether JDA should fireRawGatewayEvent
for every discord event.JDABuilder
setRelativeRateLimit(boolean enable)
Whether the rate-limit should be relative to the current time plus latency.JDABuilder
setRequestTimeoutRetry(boolean retryOnTimeout)
Whether the Requester should retry when aSocketTimeoutException
occurs.JDABuilder
setSessionController(SessionController controller)
Sets theSessionController
for this JDABuilder instance.JDABuilder
setStatus(OnlineStatus status)
Sets theOnlineStatus
our connection will display.JDABuilder
setToken(java.lang.String token)
JDABuilder
setVoiceDispatchInterceptor(VoiceDispatchInterceptor interceptor)
Configures a custom voice dispatch handler which handles audio connections.JDABuilder
setWebsocketFactory(WebSocketFactory factory)
Sets theWebSocketFactory
that will be used by JDA's websocket client.JDABuilder
useSharding(int shardId, int shardTotal)
This will enable sharding mode for JDA.
-
-
-
Method Detail
-
createDefault
@Nonnull @CheckReturnValue public static JDABuilder createDefault(@Nullable java.lang.String token)
Creates a JDABuilder 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 JDABuilder
- See Also:
disableIntents(GatewayIntent, GatewayIntent...)
,enableIntents(GatewayIntent, GatewayIntent...)
-
createDefault
@Nonnull @CheckReturnValue public static JDABuilder createDefault(@Nullable java.lang.String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
Creates a JDABuilder 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 JDABuilder
- Throws:
java.lang.IllegalArgumentException
- If provided with null intents
-
createDefault
@Nonnull @CheckReturnValue public static JDABuilder createDefault(@Nullable java.lang.String token, @Nonnull java.util.Collection<GatewayIntent> intents)
Creates a JDABuilder 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 JDABuilder
- Throws:
java.lang.IllegalArgumentException
- If provided with null intents
-
createLight
@Nonnull @CheckReturnValue public static JDABuilder createLight(@Nullable java.lang.String token)
Creates a JDABuilder 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 JDABuilder
- See Also:
disableIntents(GatewayIntent, GatewayIntent...)
,enableIntents(GatewayIntent, GatewayIntent...)
-
createLight
@Nonnull @CheckReturnValue public static JDABuilder createLight(@Nullable java.lang.String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
Creates a JDABuilder 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 JDABuilder
-
createLight
@Nonnull @CheckReturnValue public static JDABuilder createLight(@Nullable java.lang.String token, @Nonnull java.util.Collection<GatewayIntent> intents)
Creates a JDABuilder 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 JDABuilder
-
create
@Nonnull @CheckReturnValue public static JDABuilder create(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
Creates a completely empty JDABuilder with the predefined intents.
You can useJDABuilder.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 JDABuilder instance
- Throws:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
create
@Nonnull @CheckReturnValue public static JDABuilder create(@Nonnull java.util.Collection<GatewayIntent> intents)
Creates a completely empty JDABuilder 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 JDABuilder instance
- Throws:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
create
@Nonnull @CheckReturnValue public static JDABuilder create(@Nullable java.lang.String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
Creates a JDABuilder with the predefined token.
You can useJDABuilder.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 JDABuilder instance
- Throws:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
create
@Nonnull @CheckReturnValue public static JDABuilder create(@Nullable java.lang.String token, @Nonnull java.util.Collection<GatewayIntent> intents)
Creates a JDABuilder 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 JDABuilder instance
- Throws:
java.lang.IllegalArgumentException
- If the provided intents are null- See Also:
setToken(String)
-
setGatewayEncoding
@Nonnull public JDABuilder setGatewayEncoding(@Nonnull GatewayEncoding encoding)
Choose whichGatewayEncoding
JDA should use.- Parameters:
encoding
- TheGatewayEncoding
(default: JSON)- Returns:
- The JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If null is provided- Since:
- 4.2.1
-
setRawEventsEnabled
@Nonnull public JDABuilder setRawEventsEnabled(boolean enable)
- Parameters:
enable
- True, if JDA should fireRawGatewayEvent
.- Returns:
- The JDABuilder instance. Useful for chaining.
- Since:
- 4.0.0
-
setRelativeRateLimit
@Nonnull public JDABuilder setRelativeRateLimit(boolean enable)
Whether the rate-limit should be relative to the current time plus latency.
By default we use theX-RateLimit-Reset-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 JDABuilder 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 JDABuilder 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 selective 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 JDABuilder instance. Useful for chaining.
- See Also:
setDisabledCacheFlags(EnumSet)
-
enableCache
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableCache(CacheFlag, CacheFlag...)
,disableCache(Collection)
-
enableCache
@Nonnull public JDABuilder 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 JDABuilder 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 JDABuilder 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 JDABuilder instance. Useful for chaining.
-
disableCache
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
disableCache(CacheFlag, CacheFlag...)
,enableCache(Collection)
-
disableCache
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
disableCache(Collection)
,enableCache(CacheFlag, CacheFlag...)
-
setMemberCachePolicy
@Nonnull public JDABuilder 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(JDABuilder 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); builder.setMemberCachePolicy(policy); }
- Parameters:
policy
- TheMemberCachePolicy
or null to use defaultMemberCachePolicy.ALL
- Returns:
- The JDABuilder instance. Useful for chaining.
- Since:
- 4.2.0
- See Also:
MemberCachePolicy
,setEnabledIntents(Collection)
-
setContextMap
@Nonnull public JDABuilder setContextMap(@Nullable java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> map)
Sets theMDC
mappings 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
.If provided with non-null map this automatically enables MDC context using
setContextEnable(true)
!- Parameters:
map
- The modifiable context map to use in JDA, ornull
to reset- Returns:
- The JDABuilder instance. Useful for chaining.
- See Also:
- MDC Javadoc,
setContextEnabled(boolean)
-
setContextEnabled
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- See Also:
- MDC Javadoc,
setContextMap(java.util.concurrent.ConcurrentMap)
-
setCompression
@Nonnull public JDABuilder 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 with the gateway connection- Returns:
- The JDABuilder instance. Useful for chaining
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
- Official Discord Documentation - Transport Compression
-
setRequestTimeoutRetry
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
-
setToken
@Nonnull public JDABuilder setToken(@Nullable java.lang.String token)
Sets the token that will be used by theJDA
instance to log in whenbuild()
is called.For
AccountType.BOT
- 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 JDABuilder instance. Useful for chaining.
-
setHttpClientBuilder
@Nonnull public JDABuilder setHttpClientBuilder(@Nullable OkHttpClient.Builder builder)
Sets theBuilder
that will be used by JDAs requester.
This can be used to set things such as connection timeout and proxy.- Parameters:
builder
- The newBuilder
to use- Returns:
- The JDABuilder instance. Useful for chaining.
-
setHttpClient
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
-
setWebsocketFactory
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
-
setRateLimitPool
@Nonnull public JDABuilder 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 automatically disables the automatic shutdown of the rate-limit pool, you can enable it usingsetRateLimitPool(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.- Parameters:
pool
- The thread-pool to use for rate-limit handling- Returns:
- The JDABuilder instance. Useful for chaining.
-
setRateLimitPool
@Nonnull public JDABuilder 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 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.- Parameters:
pool
- The thread-pool to use for rate-limit handlingautomaticShutdown
- WhetherJDA.shutdown()
should shutdown this pool- Returns:
- The JDABuilder instance. Useful for chaining.
-
setGatewayPool
@Nonnull public JDABuilder setGatewayPool(@Nullable java.util.concurrent.ScheduledExecutorService pool)
Sets theScheduledExecutorService
used by the main WebSocket connection for workers. These workers spend most of their lifetime sleeping because they only activate for sending messages over the gateway.
Only change this pool if you know what you're doing.
This automatically disables the automatic shutdown of the main-ws pool, you can enable it usingsetGatewayPool(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- Parameters:
pool
- The thread-pool to use for WebSocket workers- Returns:
- The JDABuilder instance. Useful for chaining.
-
setGatewayPool
@Nonnull public JDABuilder setGatewayPool(@Nullable java.util.concurrent.ScheduledExecutorService pool, boolean automaticShutdown)
Sets theScheduledExecutorService
used by the main WebSocket connection for workers. These workers spend most of their lifetime sleeping because they only activate for sending messages over the gateway.
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- Parameters:
pool
- The thread-pool to use for WebSocket workersautomaticShutdown
- WhetherJDA.shutdown()
should shutdown this pool- Returns:
- The JDABuilder instance. Useful for chaining.
-
setCallbackPool
@Nonnull public JDABuilder 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 pool, 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 JDABuilder instance. Useful for chaining.
-
setCallbackPool
@Nonnull public JDABuilder 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 shutdown this executor- Returns:
- The JDABuilder instance. Useful for chaining.
-
setEventPool
@Nonnull public JDABuilder 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 JDA 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 JDABuilder instance. Useful for chaining.
- Since:
- 4.2.0
-
setEventPool
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Since:
- 4.2.0
-
setAudioPool
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Since:
- 4.2.1
-
setAudioPool
@Nonnull public JDABuilder 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
- WhetherJDA.shutdown()
should shutdown this pool- Returns:
- The JDABuilder instance. Useful for chaining.
- Since:
- 4.2.1
-
setBulkDeleteSplittingEnabled
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
-
setEnableShutdownHook
@Nonnull public JDABuilder setEnableShutdownHook(boolean enable)
Enables/Disables the use of a Shutdown hook to clean up JDA.
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 JDA if the Java program is closed.- Returns:
- Return the
JDABuilder
instance. Useful for chaining.
-
setAutoReconnect
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
-
setEventManager
@Nonnull public JDABuilder setEventManager(@Nullable IEventManager manager)
Changes 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 JDABuilder instance. Useful for chaining.
-
setAudioSendFactory
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
-
setIdle
@Nonnull public JDABuilder setIdle(boolean idle)
Sets whether or not we should mark our session as afk
This value can be changed at any time in thePresence
from a JDA instance.- Parameters:
idle
- boolean value that will be provided with our IDENTIFY package to mark our session as afk or not. (default false)- Returns:
- The JDABuilder instance. Useful for chaining.
- See Also:
Presence.setIdle(boolean)
-
setActivity
@Nonnull public JDABuilder 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)
.- Parameters:
activity
- An instance ofActivity
(null allowed)- Returns:
- The JDABuilder instance. Useful for chaining.
- See Also:
Presence.setActivity(Activity)
-
setStatus
@Nonnull public JDABuilder setStatus(@Nonnull 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- if the provided OnlineStatus is null orUNKNOWN
- See Also:
Presence.setStatus(OnlineStatus)
-
addEventListeners
@Nonnull public JDABuilder addEventListeners(@Nonnull java.lang.Object... listeners)
Adds all provided listeners to the list of listeners that will be used to populate theJDA
object.
This uses theInterfacedEventListener
by default.
To switch to theAnnotatedEventManager
, usesetEventManager(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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If either listeners or one of it's objects isnull
.- See Also:
JDA.addEventListener(Object...)
-
removeEventListeners
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If either listeners or one of it's objects isnull
.- See Also:
JDA.removeEventListener(Object...)
-
setMaxReconnectDelay
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- Thrown if the providedmaxReconnectDelay
is less than 32.
-
useSharding
@Nonnull public JDABuilder useSharding(int shardId, int shardTotal)
This will enable sharding mode for JDA.
In sharding mode, guilds are split up and assigned one of multiple shards (clients).
The shardId that receives all stuff related to given bot is calculated as follows: shardId == (guildId >> 22) % shardTotal;
PMs are only sent to shard 0.Please note, that a shard will not know about guilds which are not assigned to it.
- Parameters:
shardId
- The id of this shard (starting at 0).shardTotal
- The number of overall shards.- Returns:
- The JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If the provided shard configuration is invalid (0 <= shardId < shardTotal
withshardTotal > 0
)- See Also:
JDA.getShardInfo()
,ShardManager
-
setSessionController
@Nonnull public JDABuilder setSessionController(@Nullable SessionController controller)
Sets theSessionController
for this JDABuilder 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.
WhenuseSharding(int, int)
is enabled, this is set by default.When set, this allows the builder to build shards with respect to the login ratelimit automatically.
- Parameters:
controller
- TheSessionController
to use- Returns:
- The JDABuilder instance. Useful for chaining.
- See Also:
SessionControllerAdapter
-
setVoiceDispatchInterceptor
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Since:
- 4.0.0
- See Also:
VoiceDispatchInterceptor
-
setChunkingFilter
@Nonnull public JDABuilder setChunkingFilter(@Nullable ChunkingFilter filter)
TheChunkingFilter
to filter which guilds should use member chunking.If a guild is configured for chunking the
setMemberCachePolicy(MemberCachePolicy)
will be ignored.- Parameters:
filter
- The filter to apply- Returns:
- The JDABuilder instance. Useful for chaining.
- Since:
- 4.1.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 JDABuilder setGuildSubscriptionsEnabled(boolean enabled)
Deprecated.This is now superseded 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 JDABuilder instance. Useful for chaining.
- Since:
- 4.1.0
-
setDisabledIntents
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If null is provided- Since:
- 4.2.0
- See Also:
setMemberCachePolicy(MemberCachePolicy)
-
setDisabledIntents
@Nonnull public JDABuilder 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 (default: none)- Returns:
- The JDABuilder instance. Useful for chaining.
- Since:
- 4.2.0
- See Also:
setMemberCachePolicy(MemberCachePolicy)
-
disableIntents
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableIntents(Collection)
-
disableIntents
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableIntents(GatewayIntent, GatewayIntent...)
-
setEnabledIntents
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If null is provided- Since:
- 4.2.0
- See Also:
setMemberCachePolicy(MemberCachePolicy)
-
setEnabledIntents
@Nonnull public JDABuilder 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 (default: all)- Returns:
- The JDABuilder instance. Useful for chaining.
- Since:
- 4.2.0
- See Also:
setMemberCachePolicy(MemberCachePolicy)
-
enableIntents
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
disableIntents(Collection)
-
enableIntents
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If provided with null- See Also:
enableIntents(GatewayIntent, GatewayIntent...)
-
setLargeThreshold
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Since:
- 4.1.0
-
setMaxBufferSize
@Nonnull public JDABuilder 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 JDABuilder instance. Useful for chaining.
- Throws:
java.lang.IllegalArgumentException
- If the provided buffer size is negative
-
build
@Nonnull public JDA build() throws javax.security.auth.login.LoginException
Builds a newJDA
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,JDA
has not finished loading, thus manyJDA
methods have the chance to return incorrect information. For exampleJDA.getGuilds()
might return an empty list orJDA.getUserById(long)
might return null for arbitrary user IDs.If you wish to be sure that the
JDA
information is correct, please useJDA.awaitReady()
or register anEventListener
to listen for theReadyEvent
.- Returns:
- A
JDA
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.- See Also:
JDA.awaitReady()
-
-