/Javacord

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

Primary LanguageJavaApache License 2.0Apache-2.0

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.2' }

Maven

<dependency>
    <groupId>org.javacord</groupId>
    <artifactId>javacord</artifactId>
    <version>3.0.2</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.