Discord4J

A fast and reactive JVM-based REST/WS wrapper for the official Discord Bot API, written in Java

Github星跟蹤圖

Discord4J

Support Server Invite
Maven Central
Javadocs
CircleCI branch

A fast, reactive Java wrapper for the official Discord Bot API.

Built with Reactor, Netty, and a focus on flexibility, Discord4J provides an effective, non-blocking interface for creating Discord bots. The reactive and asynchronous nature of the library allows for scalability through backpressure handling and the efficient use of resources. Its modularized structure gives the user the ability to tailor their experience to different levels of abstraction and pick the right tools for the job.

Installation

Our current stable line is 3.0.x

Gradle

repositories {
  mavenCentral()
}

dependencies {
  implementation 'com.discord4j:discord4j-core:3.0.12'
}

Maven

<dependencies>
  <dependency>
    <groupId>com.discord4j</groupId>
    <artifactId>discord4j-core</artifactId>
    <version>3.0.12</version>
  </dependency>
</dependencies>

SBT

libraryDependencies ++= Seq(
  "com.discord4j" % "discord4j-core" % "3.0.12"
)

Quick Example (Reactive and Blocking)

final DiscordClient client = new DiscordClientBuilder("token").build();

client.getEventDispatcher().on(ReadyEvent.class)
        .subscribe(ready -> System.out.println("Logged in as " + ready.getSelf().getUsername()));

client.getEventDispatcher().on(MessageCreateEvent.class)
        .map(MessageCreateEvent::getMessage)
        .filter(msg -> msg.getContent().map("!ping"::equals).orElse(false))
        .flatMap(Message::getChannel)
        .flatMap(channel -> channel.createMessage("Pong!"))
        .subscribe();

client.login().block();
final DiscordClient client = new DiscordClientBuilder("token").build();

client.getEventDispatcher().on(ReadyEvent.class)
        .subscribe(ready -> System.out.println("Logged in as " + ready.getSelf().getUsername()));

client.getEventDispatcher().on(MessageCreateEvent.class)
        .subscribe(event -> {
            Message message = event.getMessage();
            if (message.getContent().map("!ping"::equals).orElse(false)) {
                message.getChannel().block().createMessage("Pong!").block();
            }
         });

client.login().block();

Modules

Discord4J is highly oriented towards customizability. To achieve this, the project is divided into several "modules" which can be used separately depending on your use case.

Core

The core module combines the other modules to form high-level abstractions for the entire Discord Bot API. This is the module most users will want when making bots.

Rest

The rest module provides a low-level HTTP client specifically for Discord which properly handles Discord's ratelimiting system.

Gateway

The gateway module provides a low-level WebSocket client for interacting with the Discord Gateway.

Voice

The voice module provides a client to manipulate audio through Voice Connections.

Common

The common module contains base utilities and models useful for other modules.

Stores

Discord4J's mechanism for storing information received on the gateway is completely pluggable. This allows both the ability to customize what is stored and how. The Stores repository contains some pre-made implementations as well as the API for making your own.

Development builds (v3.1)

Jitpack

Please follow our instructions at Using Jitpack

Snapshots

Make sure you have the appropriate repositories, using Gradle:

repositories {
  maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
  mavenCentral()
}

dependencies {
  implementation 'com.discord4j:discord4j-core:3.1.0-SNAPSHOT'
}

And using Maven:

<repositories>
    <repository>
        <id>oss.sonatype.org-snapshot</id>
        <url>http://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.discord4j</groupId>
        <artifactId>discord4j-core</artifactId>
        <version>3.1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

主要指標

概覽
名稱與所有者Discord4J/Discord4J
主編程語言Java
編程語言Java (語言數: 1)
平台
許可證GNU Lesser General Public License v3.0
所有者活动
創建於2015-11-07 21:29:08
推送於2025-05-06 15:51:44
最后一次提交2025-05-06 11:46:39
發布數106
最新版本名稱3.3.0-RC2 (發布於 2025-04-29 12:35:14)
第一版名稱2.0.0 (發布於 )
用户参与
星數1.8k
關注者數37
派生數267
提交數4.1k
已啟用問題?
問題數537
打開的問題數21
拉請求數624
打開的拉請求數1
關閉的拉請求數125
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?