public class JDABuilder
extends java.lang.Object
JDA
instance. This is useful for making sure all of
your EventListeners
as registered
before JDA
attempts to log in.
A single JDABuilder can be reused multiple times. Each call to
buildAsync()
or
buildBlocking()
creates a new JDA
instance using the same information.
This means that you can have listeners easily registered to multiple JDA
instances.
Constructor and Description |
---|
JDABuilder(AccountType accountType)
Creates a completely empty JDABuilder.
If you use this, you need to set the token using setBotToken(String)
before calling buildAsync()
or buildBlocking() |
Modifier and Type | Method and Description |
---|---|
JDABuilder |
addListener(java.lang.Object... listeners)
Adds all provided listeners to the list of listeners that will be used to populate the
JDA object. |
JDA |
buildAsync()
|
JDA |
buildBlocking()
Builds a new
JDA instance and uses the provided token to start the login process.This method will block until JDA has logged in and finished loading all resources. |
JDABuilder |
removeListener(java.lang.Object... listeners)
Removes all provided listeners from the list of listeners.
|
JDABuilder |
setAudioEnabled(boolean enabled)
Enables/Disables Voice functionality.
This is useful, if your current system doesn't support Voice and you do not need it. |
JDABuilder |
setAutoReconnect(boolean autoReconnect)
Sets whether or not JDA should try to reconnect, if a connection-error occured.
|
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 |
setEnableShutdownHook(boolean enable)
Enables/Disables the use of a Shutdown hook to clean up JDA.
When the Java program closes shutdown hooks are run. |
JDABuilder |
setEventManager(IEventManager manager)
Changes the internally used EventManager.
|
JDABuilder |
setGame(Game game)
Sets the
Game for our session. |
JDABuilder |
setIdle(boolean idle)
Sets whether or not we should mark our session as afk
|
JDABuilder |
setProxy(org.apache.http.HttpHost proxy)
Sets the proxy that will be used by ALL JDA instances.
Once this is set IT CANNOT BE CHANGED. After a JDA instance as been created, this method can never be called again, even if you are creating a new JDA object. Note: currently this only supports HTTP proxies. |
JDABuilder |
setStatus(OnlineStatus status)
Sets the
OnlineStatus our connection will display. |
JDABuilder |
setToken(java.lang.String token)
Sets the botToken that will be used by the
JDA instance to log in when
buildAsync()
or buildBlocking()
is called. |
JDABuilder |
useSharding(int shardId,
int numShards)
This will enable sharding mode for JDA.
|
public JDABuilder(AccountType accountType)
setBotToken(String)
before calling buildAsync()
or buildBlocking()
accountType
- The AccountType
.public JDABuilder setToken(java.lang.String token)
JDA
instance to log in when
buildAsync()
or buildBlocking()
is called.token
- The token of the bot-account that you would like to login with.JDABuilder
instance. Useful for chaining.public JDABuilder setProxy(org.apache.http.HttpHost proxy)
proxy
- The proxy to use.JDABuilder
instance. Useful for chaining.java.lang.UnsupportedOperationException
- If this method is called after proxy settings have already been set or after at least 1 JDA object has been created.public JDABuilder setAudioEnabled(boolean enabled)
Default: true (enabled)
enabled
- True - enables voice support.JDABuilder
instance. Useful for chaining.public JDABuilder setBulkDeleteSplittingEnabled(boolean enabled)
MessageBulkDeleteEvent
Default: true (enabled)
enabled
- True - The MESSAGE_DELTE_BULK will be split into multiple individual MessageDeleteEvents.JDABuilder
instance. Useful for chaining.public JDABuilder setEnableShutdownHook(boolean enable)
Default: true (enabled)
enable
- True (default) - use shutdown hook to clean up JDA if the Java program is closed.JDABuilder
instance. Useful for chaining.public JDABuilder setAutoReconnect(boolean autoReconnect)
autoReconnect
- If true - enables autoReconnectJDABuilder
instance. Useful for chaining.public JDABuilder setEventManager(IEventManager manager)
InterfacedEventManager
which uses the Interface EventListener
(tip: use the ListenerAdapter
). This is the default EventManager.AnnotatedEventManager
which uses the Annotation SubscribeEvent
to mark the methods that listen for events.IEventManager
).manager
- The new IEventManager
to useJDABuilder
instance. Useful for chaining.public JDABuilder setIdle(boolean idle)
This value can be changed at any time in the Presence
from a JDA instance.
idle
- boolean value that will be provided with our IDENTIFY package to mark our session as afk or not. (default false)JDABuilder
instance. Useful for chaining.Presence.setIdle(boolean)
public JDABuilder setGame(Game game)
Game
for our session.
This value can be changed at any time in the Presence
from a JDA instance.
game
- An instance of Game
(null allowed)JDABuilder
instance. Useful for chaining.Presence.setGame(Game)
public JDABuilder setStatus(OnlineStatus status)
OnlineStatus
our connection will display.
This value can be changed at any time in the Presence
from a JDA instance.
This will not take affect for AccountType#CLIENT
if the status specified in the user_settings
is not "online" as it is overriding our identify status.
status
- Not-null OnlineStatus (default online)JDABuilder
instance. Useful for chaining.java.lang.IllegalArgumentException
- if the provided OnlineStatus is null or UNKNOWN
Presence.setStatus(OnlineStatus)
public JDABuilder addListener(java.lang.Object... listeners)
JDA
object.
This uses the InterfacedEventListener
by default.
To switch to the AnnotatedEventManager
,
use setEventManager(new AnnotatedEventManager())
.
Note: when using the InterfacedEventListener
(default),
given listener must be instance of EventListener
!listeners
- The listeners to add to the list.JDABuilder
instance. Useful for chaining.public JDABuilder removeListener(java.lang.Object... listeners)
listeners
- The listeners to remove from the list.JDABuilder
instance. Useful for chaining.public JDABuilder useSharding(int shardId, int numShards)
shardId
- The id of this shard (starting at 0).numShards
- The number of overall shards.JDABuilder
instance. Useful for chaining.public JDA buildAsync() throws javax.security.auth.login.LoginException, java.lang.IllegalArgumentException, RateLimitedException
JDA
instance and uses the provided token to start the login process.JDA
has not
finished loading, thus many JDA
methods have the chance to return incorrect information.
If you wish to be sure that the JDA
information is correct, please use
buildBlocking()
or register a
ReadyEvent
EventListener
.
JDA
instance that has started the login process. It is unknown as to whether or not loading has finished when this returns.javax.security.auth.login.LoginException
- If the provided token is invalid.java.lang.IllegalArgumentException
- If the provided token is empty or null.RateLimitedException
- If we are being Rate limited.public JDA buildBlocking() throws javax.security.auth.login.LoginException, java.lang.IllegalArgumentException, java.lang.InterruptedException, RateLimitedException
JDA
instance and uses the provided token to start the login process.ReadyEvent
.JDA
Object that is guaranteed to be logged in and finished loading.javax.security.auth.login.LoginException
- If the provided token is invalid.java.lang.IllegalArgumentException
- If the provided token is empty or null.java.lang.InterruptedException
- If an interrupt request is received while waiting for JDA
to finish logging in.
This would most likely be caused by a JVM shutdown request.RateLimitedException
- If we are being Rate limited.