Skip to content

Latest commit

 

History

History
54 lines (45 loc) · 1.82 KB

README.md

File metadata and controls

54 lines (45 loc) · 1.82 KB

Discord4J 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.

The main features of this module include the high-level DiscordClient and representations of Discord's entities. These wrap the behavior of the rest and gateway to receive data and interact with Discord as well as the store module to optionally and efficiently store this data.

Installation

Just replace @VERSION@ with the latest given by

Gradle

repositories {
  mavenCentral()
}

dependencies {
  implementation 'com.discord4j:discord4j-core:@VERSION@'
}

Maven

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

SBT

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

Development builds

Please follow our instructions at Using Jitpack

Example Usage

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(content -> content.equals("!ping")).orElse(false))
        .flatMap(Message::getChannel)
        .flatMap(channel -> channel.createMessage("Pong!"))
        .subscribe();

client.login().block();