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 static boolean |
jdaCreated |
protected static int |
proxyPort |
protected static boolean |
proxySet |
protected static java.lang.String |
proxyUrl |
Constructor and Description |
---|
JDABuilder()
Creates a completely empty JDABuilder.
If you use this, you need to set the email and password using setEmail(String)
and setPassword(String)
before calling buildAsync()
or buildBlocking() |
JDABuilder(java.lang.String email,
java.lang.String password)
Creates a new JDABuilder using the provided email and password.
|
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 |
build()
Deprecated.
|
JDA |
buildAsync()
|
JDA |
buildBlocking()
Builds a new
JDA instance and uses the provided email and password 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 |
setDebug(boolean debug)
Enables developer debug of JDA.
Enabling this will print stack traces instead of java logger message when exceptions are encountered. |
JDABuilder |
setEmail(java.lang.String email)
Sets the email that will be used by the
JDA instance to log in when
buildAsync()
or buildBlocking()
is called. |
JDABuilder |
setPassword(java.lang.String password)
Sets the password that will be used by the
JDA instance to log in when
buildAsync()
or buildBlocking()
is called. |
JDABuilder |
setProxy(java.lang.String proxyUrl,
int proxyPort)
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 |
useAnnotatedEventManager(boolean useAnnotated)
Changes the internal EventManager.
|
protected static boolean proxySet
protected static boolean jdaCreated
protected static java.lang.String proxyUrl
protected static int proxyPort
public JDABuilder()
setEmail(String)
and setPassword(String)
before calling buildAsync()
or buildBlocking()
public JDABuilder(java.lang.String email, java.lang.String password)
email
- The email of the account that will be used to log into Discord.password
- The password of the account that will be used to log into Discord.public JDABuilder setEmail(java.lang.String email)
JDA
instance to log in when
buildAsync()
or buildBlocking()
is called.email
- The email of the account that you would like to login with.JDABuilder
instance. Useful for chaining.public JDABuilder setPassword(java.lang.String password)
JDA
instance to log in when
buildAsync()
or buildBlocking()
is called.password
- The password of the account that you would like to login with.JDABuilder
instance. Useful for chaining.public JDABuilder setProxy(java.lang.String proxyUrl, int proxyPort)
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 setDebug(boolean debug)
debug
- True - enables debug printing.JDABuilder
instance. Useful for chaining.public JDABuilder useAnnotatedEventManager(boolean useAnnotated)
InterfacedEventListener
.
There is also an AnnotatedEventManager
available.useAnnotated
- Whether or not to use the AnnotatedEventManager
JDABuilder
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 useAnnotatedEventManager(boolean)
.
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.@Deprecated public JDA build() throws javax.security.auth.login.LoginException, java.lang.IllegalArgumentException
buildAsync()
instead to achieve the same functionality.javax.security.auth.login.LoginException
java.lang.IllegalArgumentException
public JDA buildAsync() throws javax.security.auth.login.LoginException, java.lang.IllegalArgumentException
JDA
instance and uses the provided email and password 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 email-password combination fails the Discord security authentication.java.lang.IllegalArgumentException
- If either the provided email or password is empty or null.public JDA buildBlocking() throws javax.security.auth.login.LoginException, java.lang.IllegalArgumentException, java.lang.InterruptedException
JDA
instance and uses the provided email and password 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 email-password combination fails the Discord security authentication.java.lang.IllegalArgumentException
- If either the provided email or password 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.