Skip to content
An easy to use multithreaded library for creating Discord bots in Java.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Fix OOM killer problem on CircleCI Dec 27, 2018
.github [Gradle Release Plugin] - pre tag commit: 'v3.0.4'. Apr 9, 2019
config/checkstyle
gradle Allow event listener registration during construction of the DiscordApi Apr 7, 2019
javacord-api/src/main Add isBotUser() and isRegularUser() to MessageAuthor Apr 9, 2019
javacord-core/src Allow event listener registration during construction of the DiscordApi Apr 7, 2019
.gitignore Add second-level out directories to .gitignore Jun 22, 2018
LICENSE Update license Feb 28, 2018
README.md [Gradle Release Plugin] - pre tag commit: 'v3.0.4'. Apr 9, 2019
build.gradle Remove unused Gradle plugin Aug 6, 2018
gradle.properties [Gradle Release Plugin] - pre tag commit: 'v3.0.4'. Apr 9, 2019
gradlew Replace Maven by Gradle Mar 26, 2018
gradlew.bat Replace Maven by Gradle Mar 26, 2018
jitpack.yml Use openjdk10 instead of oraclejdk9 on JitPack Jul 25, 2018
settings.gradle Upgrade to Gradle 4.8.1 Jun 29, 2018

README.md

Javacord Latest version Latest JavaDocs Javacord Wiki Javacord Discord server

An easy to use multithreaded library for creating Discord bots in Java.

Feature Coverage

Javacord supports every action a Discord bot is able to perform.
Some of these features include, but are not limited to:

  • sending messages
  • attaching files
  • event listening
  • user management
  • server administration
  • ... and many others

Sending voice will be added in an upcoming release.
New features introduced by Discord are typically added in less than one week, depending on scale.

Download / Installation

The recommended way to get Javacord is to use a build manager, like Gradle or Maven.
If you are not familiar with build managers, you can follow this Setup Guide or download Javacord directly from GitHub.

Javacord Dependency

Gradle

repositories { mavenCentral() }
dependencies { implementation 'org.javacord:javacord:3.0.4' }

Maven

<dependency>
    <groupId>org.javacord</groupId>
    <artifactId>javacord</artifactId>
    <version>3.0.4</version>
    <type>pom</type>
</dependency>

Optional Logger Dependency

Any Log4j-2-compatible logging framework can be used to provide a more sophisticated logging experience with being able to configure log format, log targets (console, file, database, Discord direct message, ...), log levels per class, and much more.

For example, Log4j Core in Gradle

dependencies { runtimeOnly 'org.apache.logging.log4j:log4j-core:2.11.0' }

Take a look at the Logger Configuration wiki article for further information.

IDE Setup

If you have never used Gradle or Maven before, you should take a look at one of the setup tutorials:

Support

Javacord's Discord community is an excellent resource if you have questions about the library.

Documentation

  • The Javacord Wiki is a great place to get started
  • Additional documentation can be found in the JavaDoc

Logging in

Logging in is very simple

public class MyFirstBot {

    public static void main(String[] args) {
        // Insert your bot's token here
        String token = "your token";

        DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();

        // Add a listener which answers with "Pong!" if someone writes "!ping"
        api.addMessageCreateListener(event -> {
            if (event.getMessageContent().equalsIgnoreCase("!ping")) {
                event.getChannel().sendMessage("Pong!");
            }
        });

        // Print the invite url of your bot
        System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
    }

}

You can also login non-blocking asynchronously

public class MyFirstBot {

    public static void main(String[] args) {
        // Insert your bot's token here
        String token = "your token";

        new DiscordApiBuilder().setToken(token).login().thenAccept(api -> {
                    // Add a listener which answers with "Pong!" if someone writes "!ping"
                    api.addMessageCreateListener(event -> {
                        if (event.getMessageContent().equalsIgnoreCase("!ping")) {
                            event.getChannel().sendMessage("Pong!");
                        }
                    });

                    // Print the invite url of your bot
                    System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
                })
                // Log any exceptions that happened
                .exceptionally(ExceptionLogger.get());
    }

}

Check out the Example Bot to learn more.

How to create a bot user and get its token

Version numbers

The version number has a 3-digit format: major.minor.trivial

  • major: Increased extremely rarely to mark a major release (usually a rewrite affecting very huge parts of the library). You can expect this digit to not change for several years.
  • minor: Any backwards incompatible change to the api. You can expect this digit to change about 1-3 times per year.
  • trivial: A backwards compatible change to the api. This is usually an important bugfix (or a bunch of smaller ones) or a backwards compatible feature addition. You can expect this digit to change 1-2 times per month.

Deprecation policy

A method or class that is marked as deprecated can be removed with the next minor release (but it will usually stay for several minor releases). A minor release might remove a class or method without having it deprecated, but we will do our best to deprecate it before removing it. We are unable to guarantee this though, because we might have to remove / replace something due to changes made by Discord, which we are unable to control. Usually you can expect a deprecated method or class to stay for at least 6 months before it finally gets removed, but this is not guaranteed.

Discord Server

Join the Javacord Server for support, status updates, or just chatting with other users.

You can’t perform that action at this time.