Class DiscordApiBuilder



  • public class DiscordApiBuilder
    extends Object
    This class is used to login to a Discord account.
    • Constructor Detail

      • DiscordApiBuilder

        public DiscordApiBuilder​()
    • Method Detail

      • 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 call setCurrentShard(int) with anything but 0 before calling this method.
        Parameters:
        shardsCondition - The predicate for identifying shards to connect, starting with 0!
        Returns:
        A collection of CompletableFutures which contain the DiscordApis 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 call setCurrentShard(int) with anything but 0 before calling this method.
        Parameters:
        shards - The shards to connect, starting with 0!
        Returns:
        A collection of CompletableFutures which contain the DiscordApis 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 to 1.
        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 with 0!
        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 the DiscordApi.getServers() method will return an empty collection directly after logging in and fire ServerBecomesAvailableEvent events once they become available. You can check the ids of unavailable servers using the DiscordApi.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