Skip to content

A command system for JDA that allows to treat slash and text commands the same

License

Notifications You must be signed in to change notification settings

JDiscordBots/command-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command Framework

A command system for JDA that allows to treat slash and text commands the same

Usage

  1. Add Command-Framework to the dependencies section of your pom.xml (replace VERSION with Maven Central):
<dependencies>
	<dependency>
		<groupId>io.github.jdiscordbots</groupId>
		<artifactId>command-framework</artifactId>
		<version>VERSION</version>
		<scope>compile</scope>
	</dependency>
</dependencies>
  1. Create an instance of CommandFramework
  2. Set prefix, owners etc.
  3. Build the command listener using CommandFramework#build() and add it to your JDA(Builder) instance as an event listener
  4. Create command classes which are annotated by @Command("commandname") and implement the ICommand interface
  5. See how it works perfectly

Working example:

Main:

public class Main {
    public static void main(String[] args) throws LoginException {
    		final JDABuilder builder = JDABuilder.createDefault("your token");
    		final CommandFramework framework = new CommandFramework() // Step 1
                    /* Step 2 */
    				.setMentionPrefix(true) // Allow mention prefix, Default: true
    				.setPrefix("prefix") // Default: !
    				.setOwners("owner1", "optional owner 2", "...", "optional owner n"); // Set owners for permissions system, Default: {}
    
    		builder.addEventListeners(framework.build()).build(); // Step 3
    	}
}

Example command:

import io.github.jdiscordbots.command_framework.command.*;

@Command({"example", "examplealias"}) // Step 4
public class Example implements ICommand {
    @Override
    public void action(CommandEvent event) {
        event.getChannel().sendMessage("Example command reply").queue();
    }

    @Override
    public String help() {
        return "Example command";
    }
}

Example permission restricted command:

import io.github.jdiscordbots.command_framework.command.*;

import net.dv8tion.jda.api.Permission;

@Command({"permissionexample", "permissionexamplealias"}) // Step 4
public class PermissionExample implements ICommand {
    @Override
    public void action(CommandEvent event) {
        event.getChannel().sendMessage("Permission example command reply").queue();
    }
    
    @Override
    public boolean allowExecute(CommandEvent event) {
        return event.getMember().hasPermission(Permission.MANAGE_PERMISSIONS); // Allow use of command only to members with manage permissions permission
    }

    @Override
    public String help() {
        return "Permission example command";
    }
}

Docs

You can take a look at the JavaDoc at javadoc.io.