# Discord4J
<a href="https://discord4j.com"><img align="right" src="https://raw.githubusercontent.com/Discord4J/discord4j-web/master/public/logo.svg?sanitize=true" width=27%></a>
[![Support Server Invite](https://img.shields.io/discord/208023865127862272.svg?color=7289da&label=Discord4J&logo=discord&style=flat-square)](https://discord.gg/d4j)
[![Maven Central](https://img.shields.io/maven-central/v/com.discord4j/discord4j-core/3.2.svg?style=flat-square)](https://search.maven.org/artifact/com.discord4j/discord4j-core)
[![Javadocs](https://javadoc.io/badge2/com.discord4j/discord4j-core/3.2.5/javadoc.svg?color=blue&style=flat-square)](https://javadoc.io/doc/com.discord4j/discord4j-core/3.2.5)
[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/Discord4J/Discord4J/gradle.yml?branch=3.2.x&logo=github&style=flat-square)](https://github.com/Discord4J/Discord4J/actions)
Discord4J is a fast, powerful, unopinionated, reactive library to enable quick and easy development of Discord bots for Java, Kotlin, and other JVM languages using the official [Discord Bot API](https://discord.com/developers/docs/intro).
## ð Quick Example
In this example for v3.2, whenever a user sends a `!ping` message the bot will immediately respond with `Pong!`.
Make sure your bot has the **Message Content** intent enabled in your [developer portal](https://discord.com/developers/applications).
```java
public class ExampleBot {
public static void main(String[] args) {
String token = args[0];
DiscordClient client = DiscordClient.create(token);
GatewayDiscordClient gateway = client.login().block();
gateway.on(MessageCreateEvent.class).subscribe(event -> {
Message message = event.getMessage();
if ("!ping".equals(message.getContent())) {
MessageChannel channel = message.getChannel().block();
channel.createMessage("Pong!").block();
}
});
gateway.onDisconnect().block();
}
}
```
For a full project example, check out our example projects repository [here](https://github.com/Discord4J/example-projects).
## ð Quick Links
* [Javadocs](https://www.javadoc.io/doc/com.discord4j/discord4j-core)
* [Documentation](https://docs.discord4j.com)
* [Example Projects](https://github.com/Discord4J/example-projects)
* [More examples](https://docs.discord4j.com/examples)
* [Gateway Intents](https://discord.com/developers/docs/topics/gateway#gateway-intents)
* [Discord](https://discord.gg/d4j)
## ð Benefits
* ð **Reactive** - Discord4J follows the [reactive-streams](http://www.reactive-streams.org/) protocol to ensure Discord bots run smoothly and efficiently regardless of size.
* ð **Official** - Automatic rate limiting, automatic reconnection strategies, and consistent naming conventions are among the many features Discord4J offers to ensure your Discord bots run up to Discord's specifications and to provide the least amount of surprises when interacting with our library.
* ð ï¸ **Modular** - Discord4J breaks itself into modules to allow advanced users to interact with our API at lower levels to build minimal and fast runtimes or even add their own abstractions.
* âï¸ **Powerful** - Discord4J can be used to develop any bot, big or small. We offer many tools for developing large-scale bots from [custom distribution frameworks](https://github.com/Discord4J/connect), [off-heap caching](https://github.com/Discord4J/Stores/tree/master/redis), and its interaction with Reactor allows complete integration with frameworks such as Spring and Micronaut.
* ð« **Community** - We pride ourselves on our inclusive community and are willing to help whenever challenges arise; or if you just want to chat! We offer help ranging from Discord4J specific problems, to general programming and web development help, and even Reactor-specific questions. Be sure to visit us on our [Discord server](https://discord.gg/d4j)!
## ð¦ Installation
* [Creating a new Gradle project with IntelliJ](https://www.jetbrains.com/help/idea/getting-started-with-gradle.html) *(recommended)*
* [Creating a new Maven project with IntelliJ](https://www.jetbrains.com/help/idea/maven-support.html)
* [Creating a new Gradle project with Eclipse](https://www.vogella.com/tutorials/EclipseGradle/article.html#creating-gradle-projects)
* [Creating a new Maven project with Eclipse](https://www.vogella.com/tutorials/EclipseMaven/article.html#exercise-create-a-new-maven-enabled-project-via-eclipse)
### Gradle
```groovy
repositories {
mavenCentral()
}
dependencies {
implementation 'com.discord4j:discord4j-core:3.2.5'
}
```
### Gradle Kotlin DSL
```kotlin
repositories {
mavenCentral()
}
dependencies {
implementation("com.discord4j:discord4j-core:3.2.5")
}
```
### Maven
```xml
<dependencies>
<dependency>
<groupId>com.discord4j</groupId>
<artifactId>discord4j-core</artifactId>
<version>3.2.5</version>
</dependency>
</dependencies>
```
### SBT
```scala
libraryDependencies ++= Seq(
"com.discord4j" % "discord4j-core" % "3.2.5"
)
```
## ð Discord4J Versions
Discord4J 3.2.x includes simpler and more powerful APIs to build requests, a new entity cache and performance improvements from dependency upgrades. Check our [Migration Guide](https://docs.discord4j.com/migrating-from-v3-1-to-v3-2) for more details.
| Discord4J | Support | Gateway/API | Intents | Interactions |
|-------------------------------------------------------------|------------------|-------------|-----------------------------------|-----------------|
| [v3.3.x](https://github.com/Discord4J/Discord4J/tree/master)| In development | v9 | Mandatory, non-privileged default | Fully supported |
| [v3.2.x](https://github.com/Discord4J/Discord4J/tree/3.2.x) | Current | v8 | Mandatory, non-privileged default | Fully supported |
| [v3.1.x](https://github.com/Discord4J/Discord4J/tree/3.1.x) | Maintenance only | v6 | Optional, no intent default | Maintenance only|
See [our docs](https://docs.discord4j.com/versions) for more details about compatibility.
## ð Sponsors
We would like to give a special thanks to all of our sponsors for providing us the funding to continue developing and hosting repository resources as well as driving forward initiatives for community programs. In particular, we would like to give a special shoutout to these wonderful individuals:
* [decyg](https://github.com/d-g-n)
* [nikammerlaan](https://github.com/nikammerlaan)
* [ByteAlex](https://github.com/ByteAlex)
* [Shadorc](https://github.com/Shadorc)
## â°ï¸ Large Bots
Here are some real-world examples of large bots using Discord4J:
* [Groovy](https://groovy.bot/) - Was the second-largest bot on Discord, serving music to over 4 million servers before its shutdown in August 2021.
* [ZeroTwo](https://zerotwo.bot/) - An anime multi-purpose bot used in over 1 million servers.
* [DisCal](https://www.discalbot.com/) - Implements Google Calendar into Discord as seamlessly and comprehensively as possible; serving over 21k servers.
* [Shadbot](https://github.com/Shadorc/Shadbot) - A configurable multipurpose bot with music, gambling mini-games, video game stats, and more; serving nearly 12K servers before its shutdown in August 2021.
Do you own a large bot using Discord4J? Ask an admin in our Discord or submit a pull request to add your bot to the list!
## âï¸ Reactive
Discord4J uses [Project Reactor](https://projectreactor.io/) as the foundation for our asynchronous framework. Reactor provides a simple yet extremely powerful API that enables users to reduce resources and increase performance.
```java
public class ExampleBot {
public static void main(String[] args) {
String token = args[0];
DiscordClient client = DiscordClient.create(token);
client.login().flatMapMany(gateway -> gateway.on(MessageCreateEvent.class))