Overview of the Discord4J Library
Discord4J is a reactive Java wrapper for the official Discord Bot API. It is designed for developers who want to build Discord bots using reactive programming patterns in Java.
website·Indexed 32 days ago
https://docs.discord4j.com/A reactive wrapper library for the Discord REST API and Gateway. The documentation covers bot development, including the use of Reactor for threading, sharding, interaction components (Buttons, Select Menus, Text Inputs), and migration guides for versions v2.x through v3.3.
Discord4J uses a concurrency-agnostic runtime based on Project Reactor. Its threading model is divided by task type:
EventDispatcher using a ForkJoinPoolScheduler to avoid blocking the network event loop.Discord4J Connect enables distributed bot architectures across multiple machines using a Leader/Worker topology:
ShardCoordinator (throttling IDENTIFY), GlobalRateLimiter, Router (REST API coordination), a payload broker, and a distributed StoreService (entity cache).Common patterns include:
Mono (for 0 or 1 result) and Flux (for 0 to N results). Unlike v2, simply calling a method does not execute the action; you must 'subscribe' to the returned Mono or Flux for the operation to occur.DiscordClient is now used exclusively for REST API operations and for spawning Gateway connections. It no longer provides access to the Store abstraction for cached entities. To work with Gateway-based entities and caches, you must use GatewayDiscordClient, which is acquired by subscribing to DiscordClient::login or GatewayBootstrap::login after creation via DiscordClient::gateway.ActionRows per message.MESSAGE_CONTENT intent will now throw an UnsupportedOperationException.