Package org.javacord.api
Class DiscordApiBuilder
- java.lang.Object
-
- org.javacord.api.DiscordApiBuilder
-
public class DiscordApiBuilder extends Object
This class is used to login to a Discord account.
-
-
Constructor Summary
Constructors Constructor Description DiscordApiBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<DiscordApi>login()Login to the account with the given token.Collection<CompletableFuture<DiscordApi>>loginAllShards()Login all shards to the account with the given token.Collection<CompletableFuture<DiscordApi>>loginShards(int... shards)Login given shards to the account with the given token.Collection<CompletableFuture<DiscordApi>>loginShards(IntPredicate shardsCondition)Login shards adhering to the given predicate to the account with the given token.DiscordApiBuildersetAccountType(AccountType type)Sets the account type.DiscordApiBuildersetCurrentShard(int currentShard)Sets shard for server sharding.CompletableFuture<DiscordApiBuilder>setRecommendedTotalShards()Retrieves the recommended shards count from the Discord API and sets it in this builder.DiscordApiBuildersetToken(String token)Sets the token which is required for the login process.DiscordApiBuildersetTotalShards(int totalShards)Sets total shards for server sharding.DiscordApiBuildersetWaitForServersOnStartup(boolean waitForServersOnStartup)Sets if Javacord should wait for all servers to become available on startup.
-
-
-
Method Detail
-
login
public CompletableFuture<DiscordApi> login()
Login to the account with the given token.- Returns:
- A
CompletableFuturewhich contains the DiscordApi.
-
loginAllShards
public Collection<CompletableFuture<DiscordApi>> loginAllShards()
Login all shards to the account with the given token. It is invalid to callsetCurrentShard(int)with anything but0before calling this method.- Returns:
- A collection of
CompletableFutures which contain theDiscordApis for the shards.
-
loginShards
public Collection<CompletableFuture<DiscordApi>> loginShards(IntPredicate shardsCondition)
Login shards adhering to the given predicate to the account with the given token. It is invalid to callsetCurrentShard(int)with anything but0before calling this method.- Parameters:
shardsCondition- The predicate for identifying shards to connect, starting with0!- Returns:
- A collection of
CompletableFutures which contain theDiscordApis for the shards.
-
loginShards
public Collection<CompletableFuture<DiscordApi>> loginShards(int... shards)
Login given shards to the account with the given token. It is invalid to callsetCurrentShard(int)with anything but0before calling this method.- Parameters:
shards- The shards to connect, starting with0!- Returns:
- A collection of
CompletableFutures which contain theDiscordApis for the shards.
-
setToken
public DiscordApiBuilder setToken(String token)
Sets the token which is required for the login process. A tutorial on how to get the token can be found in the Javacord wiki.- Parameters:
token- The token to set.- Returns:
- The current instance in order to chain call methods.
-
setAccountType
public DiscordApiBuilder setAccountType(AccountType type)
Sets the account type. By default the builder assumes that you want to login to a bot account. Please notice, that public client bots are not allowed by Discord!- Parameters:
type- The account type.- Returns:
- The current instance in order to chain call methods.
-
setTotalShards
public DiscordApiBuilder setTotalShards(int totalShards)
Sets total shards for server sharding. Sharding allows you to split your bot into several independent instances. A shard only handles a subset of a bot's servers.- Parameters:
totalShards- The total amount of shards. Sharding will be disabled if set to1.- Returns:
- The current instance in order to chain call methods.
- See Also:
- API docs
-
setCurrentShard
public DiscordApiBuilder setCurrentShard(int currentShard)
Sets shard for server sharding. Sharding allows you to split your bot into several independent instances. A shard only handles a subset of a bot's servers.- Parameters:
currentShard- The shard of this connection starting with0!- Returns:
- The current instance in order to chain call methods.
- See Also:
- API docs
-
setWaitForServersOnStartup
public DiscordApiBuilder setWaitForServersOnStartup(boolean waitForServersOnStartup)
Sets if Javacord should wait for all servers to become available on startup. If this is disabled theDiscordApi.getServers()method will return an empty collection directly after logging in and fireServerBecomesAvailableEventevents once they become available. You can check the ids of unavailable servers using theDiscordApi.getUnavailableServers()method.- Parameters:
waitForServersOnStartup- Whether Javacord should wait for all servers to become available on startup or not.- Returns:
- The current instance in order to chain call methods.
-
setRecommendedTotalShards
public CompletableFuture<DiscordApiBuilder> setRecommendedTotalShards()
Retrieves the recommended shards count from the Discord API and sets it in this builder. Sharding allows you to split your bot into several independent instances. A shard only handles a subset of a bot's servers.- Returns:
- A future with the current api builder.
- See Also:
- API docs
-
-