Shredder121-me/JDA


Java REST wrapper for the popular chat & VOIP service: Discord. https://discordapp.com/

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.Shredder121-me:JDA:v3.1.0'
	}
	dependencies {
		implementation("com.github.Shredder121-me:JDA:v3.1.0")
	}
	<dependency>
	    <groupId>com.github.Shredder121-me</groupId>
	    <artifactId>JDA</artifactId>
	    <version>v3.1.0</version>
	</dependency>

                            
    libraryDependencies += "com.github.Shredder121-me" % "JDA" % "v3.1.0"
        
        

                            
    :dependencies [[com.github.Shredder121-me/JDA "v3.1.0"]]
        
        

Readme


JDA (Java Discord API)

JDA strives to provide a clean and full wrapping of the Discord REST api and its Websocket-Events for Java.

JDA 3.x

JDA will be continued with version 3.x and will support Bot-features (for bot-accounts) and Client-features (for user-accounts). Please see the Discord docs for more information about bot accounts.

This officially makes JDA-Client deprecated. Please do not continue using it, and instead switch to the promoted 3.x version listed further below.

Creating the JDA Object

Creating the JDA Object is done via the JDABuilder class by providing an AccountType (Bot/Client). After setting the token via setter, the JDA Object is then created by calling the .buildBlocking() or the .buildAsync() (non-blocking login) method.

Example:

JDA jda = new JDABuilder(AccountType.BOT).setToken("token").buildBlocking();

Note: It is important to set the correct AccountType because Bot-accounts require a token prefix to login.

Events

There are a TON of events in JDA that you can listen to.<br> Currently, there are 2 ways of writing your Event-Listener: 1. Extend ListenerAdapter and use the provided methods that get fired depending on the Event-Type. Event Methods 2. Implement EventListener and listen to onEvent and figure out if it is the event you want (Not suggested)<br>

Listeners can be registered either in the JDABuilder (will catch all Events; recommended), or in the JDA instance (initial Events, especially the READY-Event could get lost)

Examples:

public class ReadyListener implements EventListener
{
    public static void main(String[] args)
            throws LoginException, RateLimitedException, InterruptedException
    {
        // Note: It is important to register your ReadyListener before building
        JDA jda = new JDABuilder(AccountType.BOT)
            .setToken("token")
            .addEventListener(new ReadyListener())
            .buildBlocking();
    }

    @Override
    public void onEvent(Event event)
    {
        if (event instanceof ReadyEvent)
            System.out.println("API is ready!");
    }
}
public class MessageListener extends ListenerAdapter
{
    public static void main(String[] args)
            throws LoginException, RateLimitedException, InterruptedException
    {
        JDA jda = new JDABuilder(AccountType.BOT).setToken("token").buildBlocking();
        jda.addEventListener(new MessageListener());
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event)
    {
        if (event.isFromType(ChannelType.PRIVATE))
        {
            System.out.printf("[PM] %s: %s\n", event.getAuthor().getName(),
                                    event.getMessage().getContent());
        }
        else
        {
            System.out.printf("[%s][%s] %s: %s\n", event.getGuild().getName(),
                        event.getTextChannel().getName(), event.getMember().getEffectiveName(),
                        event.getMessage().getContent());
        }
    }
}

Note: In these examples we override methods from the inheriting class ListenerAdapter.<br> The usage of the @Override annotation is recommended to validate methods.

More Examples

We provide a small set of Examples in the Example Directory.

Download

Latest Version: Download

Be sure to replace the VERSION key below with the latest version shown above!

Maven

<dependency>
    <groupId>net.dv8tion</groupId>
    <artifactId>JDA</artifactId>
    <version>VERSION</version>
</dependency>

<repository>
    <id>jcenter</id>
    <name>jcenter-bintray</name>
    <url>http://jcenter.bintray.com</url>
</repository>

Gradle

dependencies {
    compile 'net.dv8tion:JDA:VERSION'
}

repositories {
    jcenter()
}

The builds are distributed using JCenter through Bintray JDA JCenter Bintray

Docs

Docs can be found on the Jenkins or directly here <br>A simple Wiki can also be found in this repo's Wiki section

Getting Help

If you need help, or just want to talk with the JDA or other Discord Devs, you can join the Unofficial Discord API Guild.

Once you joined, you can find JDA-specific help in the #java_jda channel<br> We have our own Discord Server here

For guides and setup help you can also take a look at the wiki

Contributing to JDA

If you want to contribute to JDA, make sure to base your branch off of our master branch (or a feature-branch) and create your PR into that same branch. We will be rejecting any PRs between branches!

It is also highly recommended to get in touch with the Devs before opening Pull Requests (either through an issue or the Discord servers mentioned above).<br> It is very possible that your change might already be in development or you missed something.

More information can be found at the wiki page 5) Contributing

Dependencies:

This project requires Java 8.<br> All dependencies are managed automatically by Gradle.