Giter Site home page Giter Site logo

jcordext's Introduction

jcordext Latest version

jcordext is a Utility Framework for Java Discord Bots which uses the Javacord Library and API.

As of right now, jcordext is limited in functionality to a Commands framework as well as a Tasks framework, which allows the bot to periodically execute "tasks" in a loop.

Installation

We do not support maven/gradle as we have yet to push this project to a repository. However, you can download the jar here. Note that Javacord has to be included separately.

Examples

The following code will create a simple bot with a "ping" command:

// in a file named Main.java
public class Main {
    public static void main(String[] args) {
        String token = "YOUR TOKEN";
        Bot bot = new Bot(PREFIX, token);
        bot.registerExtension(new cog(), "Bot");
    }
} 

// in a separate file named cog.java
public class cog implements Extension {

    @Command(
        name = "ping",
        description = "Ping the bot",
        usage = "!ping"
    )
    public void ping(Context ctx) {
        ctx.send('Pong!');
    }

}

In order to add arguments to the command you can simply add parameters to the command method:

public class cog implements Extension {

    @Command(
        name = "ping",
        description = "Ping the bot",
        usage = "!ping argument"
    )
    public void ping(Context ctx, String argument) {
        ctx.send(argument + " was sent!");
    }

}

You can also use User, Channel and Role objects in your parameters (jcordext will convert them for you):

public class cog implements Extension {

    @Command(
        name = "ping",
        description = "Ping the bot",
        usage = "!ping argument"
    )
    public void ping(Context ctx, User argument) {
        ctx.send(mention(user) + ", pong!"); // the mention() method is built into the Extension class for convenience.
    }

}

The prefix is built in and you do not need to specify the prefix in the @Command annotation. When you register the Extension to the Bot, it will automatically add the prefix.

jcordext's People

Contributors

ecxx avatar

Watchers

 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.