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.
Modifier and Type | Field and Description |
---|---|
protected AccountType |
accountType |
protected boolean |
autoReconnect |
protected boolean |
enableBulkDeleteSplitting |
protected boolean |
enableShutdownHook |
protected boolean |
enableVoice |
protected IEventManager |
eventManager |
protected static boolean |
jdaCreated |
protected java.util.List<java.lang.Object> |
listeners |
protected static org.apache.http.HttpHost |
proxy |
protected JDA.ShardInfo |
shardInfo |
protected java.lang.String |
token |
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 listener)
Adds a listener 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 listener)
Removes a listener 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 |
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 |
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.
|
protected static boolean jdaCreated
protected static org.apache.http.HttpHost proxy
protected final java.util.List<java.lang.Object> listeners
protected AccountType accountType
protected java.lang.String token
protected boolean enableVoice
protected boolean enableShutdownHook
protected boolean enableBulkDeleteSplitting
protected boolean autoReconnect
protected IEventManager eventManager
protected JDA.ShardInfo shardInfo
public JDABuilder(AccountType accountType)
setBotToken(String)
before calling buildAsync()
or buildBlocking()
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)
proxyUrl
- The url of the proxy.proxyPort
- The port of the proxy. Usually this is 8080.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 addListener(java.lang.Object listener)
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
!listener
- The listener to add to the list.JDABuilder
instance. Useful for chaining.public JDABuilder removeListener(java.lang.Object listener)
listener
- The listener 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
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