Class DiscordClient


  • public final class DiscordClient
    extends RestClient
    A high-level abstraction of common Discord4J operations such as entity retrieval through Discord API or the creation of real-time bot clients through Discord Gateway.

    Instances can be obtained by using create(String) or through builder(String). A default instance is capable of performing REST API operations locally and connecting to the Gateway by using login(), withGateway(Function) or gateway().

    • Method Detail

      • create

        public static DiscordClient create​(String token)
        Create a DiscordClient with default options, using the given token for authentication.
        Parameters:
        token - the bot token used for authentication
        Returns:
        a DiscordClient configured with the default options
      • login

        public Mono<GatewayDiscordClient> login()
        Login the client to the gateway, using the recommended amount of shards, locally coordinated. The derived GatewayDiscordClient is capable of managing these shards and providing a single EventDispatcher to publish Gateway updates and Store for entity caching.

        To further configure the Gateway connections, such as initial presence, sharding and caching options, see gateway().

        Note: Starting from v3.1, this method will return a Mono of a GatewayDiscordClient, emitting the result once shards have connected. Therefore, calling Mono.block() will now return upon connection instead of disconnection.

        Returns:
        a Mono for a handle to maintain a group of shards connected to real-time Discord Gateway, emitted once at least one connection has been made. This behavior can be configured through gateway().setAwaitConnections(true). If an error is received, it is emitted through the Mono.
      • gateway

        public GatewayBootstrap<GatewayOptions> gateway()
        Start bootstrapping a connection to the real-time Discord Gateway. The resulting builder can be configured to create a GatewayDiscordClient which groups all connecting shards providing a single EventDispatcher to publish Gateway updates and Store for entity caching.

        The following are some of the features configured by this builder:

        • Sharding configuration
        • Initial event listeners and customization
        • Gateway intents
        • Initial bot status
        • Custom entity cache factory
        • Distributed architecture options
        • Member caching options
        • Guild subscriptions
        • Threading model customization
        • Entity fetching strategy
        • Gateway and voice connection options
        Returns:
        a bootstrap to create GatewayDiscordClient instances.