Own commands - GlaubeKeinemDev/JDA-Utilities GitHub Wiki

To create you own command you have to create a class which extends the Command class.

public class ExampleCommand extends Command {

public ExampleCommand(String[] neededPermissionRoles, List<String> availableChannels) {
    super(neededPermissionRoles, availableChannels);
}

@Override
public List<String> alias() {
    return new ArrayList<>();
}

@Override
public String commandName() {
    return "test";
}

@Override
public String description() {
    return "Executes a test command";
}

@Override
public void execute(String[] strings, String s, Member member, TextChannel textChannel, Message message) {
    textChannel.sendMessage("You have executed the test command").queue();
}

}

To register the command just call the registerCommand method from the DiscordBot class. Make sure you have had setup the commandcore before.

You are able to add an array of Discord roleids only users with this role will be able to execute this command, if you enter null then everyone is be able to execute the command.

You can also add a list of Textchannel ids only in one of these Textchannel the command could be executed, if you enter null the command could be executed everywhere.

discordBot.registerCommand(new ExampleCommand(null, null));

Result:

⚠️ **GitHub.com Fallback** ⚠️