Coder Social home page Coder Social logo

pyrokinesisstudio / discord4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robot-rover/discord4j

0.0 2.0 0.0 11.47 MB

Java interface for the Discord API

Home Page: http://austinv11.github.io/Discord4J/

License: GNU General Public License v2.0

Shell 0.10% Java 99.90%

discord4j's Introduction

# Discord4J [![CircleCI](https://circleci.com/gh/austinv11/Discord4J/tree/dev.svg?style=svg)](https://circleci.com/gh/austinv11/Discord4J/tree/dev) [![Download](https://jitpack.io/v/austinv11/Discord4j.svg?style=flat-square)](https://jitpack.io/#austinv11/Discord4j) [![Coverage Status](https://coveralls.io/repos/github/austinv11/Discord4J/badge.svg?branch=dev)](https://coveralls.io/github/austinv11/Discord4J?branch=dev) [![Dependency Status](https://www.versioneye.com/user/projects/57b27840b9c824005436e491/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/57b27840b9c824005436e491) [![Support Server Invite](https://img.shields.io/badge/Join-Discord4J-7289DA.svg?style=flat-square)](https://discord.gg/NxGAeCY)

Java interface for the official Discord API, written in Java 8. The API is also available in a few other languages.

For the latest dev builds, use the short commit hash or dev-SNAPSHOT as your version.

Adding Discord4J as a dependency for a project

Given that @VERSION@ = the a version of Discord4J (this can either be a release version, the short commit hash or dev-SNAPSHOT).

With Maven

In your pom.xml add:

...
<repositories>
  ...
  <repository> <!-- This repo fixes issues with transitive dependencies -->
    <id>jcenter</id>
    <url>http://jcenter.bintray.com</url>
  </repository>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>
...
<dependencies>
  ...
  <dependency>
    <groupId>com.github.austinv11</groupId>
    <artifactId>Discord4j</artifactId>
    <version>@VERSION@</version>
   <!-- <classifier>shaded</classifier> <!-- Include this line if you want a shaded jar (all the Discord4J dependencies bundled into one jar)-->
  </dependency>
</dependencies>
...

With Gradle

In your build.gradle add:

...
repositories {
  ...
  jcenter() //This prevents issues with transitive dependencies
  maven {
    url  "https://jitpack.io"
  }
}
...
dependencies {
  ...
  compile "com.github.austinv11:Discord4j:@VERSION@"
  //compile "com.github.austinv11:Discord4j:@VERSION@:shaded" //Use this line instead of the one above it if you want a shaded jar (all the Discord4J dependencies bundled into one jar)
}
...

So, how do I use this?

Tutorials/Resources

Starting with the API

The very first thing you need to do is obtain a "DiscordClient" object. This can be done by using the ClientBuilder. Example:

public class Example {

  public static IDiscordClient getClient(String token, boolean login) { // Returns an instance of the Discord client
    ClientBuilder clientBuilder = new ClientBuilder(); // Creates the ClientBuilder instance
    clientBuilder.withToken(token); // Adds the login info to the builder
    if (login) {
      return clientBuilder.login(); // Creates the client instance and logs the client in
    } else {
      return clientBuilder.build(); // Creates the client instance but it doesn't log the client in yet, you would have to call client.login() yourself
    }
  }
}

Events

The Discord4J library is very event driven. Your bot can detect these events through the use of an event listener. There are two ways of creating an event listener:

  1. Using IListener:
public class InterfaceListener implements IListener<ReadyEvent> { // The event type in IListener<> can be any class which extends Event
  
  @Override
  public void handle(ReadyEvent event) { // This is called when the ReadyEvent is dispatched
    doCoolStuff();
  }
}
  1. Using the @EventSubscriber annotation:
public class AnnotationListener {
  
  @EventSubscriber
  public void onReadyEvent(ReadyEvent event) { // This method is called when the ReadyEvent is dispatched
    foo();
  }
  
  public void onMessageReceivedEvent(MessageReceivedEvent event) { // This method is NOT called because it doesn't have the @EventSubscriber annotation
    bar();
  }
}

Registering your listener:

public class Main {
  
  public static void main(String[] args) {
    IDiscordClient client = Example.getClient(args[0], args[1], true); // Gets the client object (from the first example)
    EventDispatcher dispatcher = client.getDispatcher(); // Gets the EventDispatcher instance for this client instance
    dispatcher.registerListener(new InterfaceListener()); // Registers the IListener example class from above
    dispatcher.registerListener(new AnnotationListener()); // Registers the @EventSubscriber example class from above
  }
}

Modules

Discord4J has an API for creating modular Discord Bots! See [Martacus's sample repo](https://github .com/Martacus/Simplecommands/tree/master) for an example as to how it works.

More examples

See the examples directory.

Projects using Discord4J

Deprecation policy

Due to the nature of the Discord API, any deprecations found in the API should not be expected to last past the current version. Meaning that if a method is deprecated on version 2.1.0, do not assume the method will be available in version 2.2.0.

Development

The Discord API is still in development. Functions may break at any time.
In such an event, please contact me or submit a pull request.

Pull requests

No one is perfect at programming and I am no exception. If you see something that can be improved, please read the contributing guildelines and feel free to submit a pull request!

Other info

More information can be found in the javadocs.

You can contact me on the Official Discord4J Server (recommended) or the Discord API server in the #java_discord4j channel.

discord4j's People

Contributors

arsenarsen avatar austinv11 avatar chrislo27 avatar darichey avatar davue avatar grandmind avatar grandpanda avatar kaioru avatar klazen108 avatar langerhans avatar malthesoelvberg avatar nerd avatar phantamanta44 avatar quanticc avatar robot-rover avatar techtony96 avatar theiglooo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.