use of net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction in project TechDiscordBot by TechsCode-Team.
the class ModulesManager method load.
public void load() {
TechDiscordBot.getJDA().updateCommands().queue();
CommandListUpdateAction commands = TechDiscordBot.getGuild().updateCommands();
for (Class<?> each : ProjectUtil.getClasses("me.TechsCode.TechDiscordBot.module")) {
if (CommandModule.class.isAssignableFrom(each) && !Modifier.isAbstract(each.getModifiers())) {
try {
CommandModule module = (CommandModule) each.getConstructor(TechDiscordBot.class).newInstance(TechDiscordBot.getBot());
if (module.getName() == null)
continue;
cmdModules.add(module);
CommandData cmdData = new CommandData(module.getName(), module.getDescription() == null ? "No description set." : module.getDescription()).addOptions(module.getOptions()).setDefaultEnabled(module.getCommandPrivileges().length == 0);
commands.addCommands(cmdData);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
} else if (Module.class.isAssignableFrom(each) && !Modifier.isAbstract(each.getModifiers())) {
try {
Module module = (Module) each.getConstructor(TechDiscordBot.class).newInstance(TechDiscordBot.getBot());
module.enable();
modules.add(module);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
}
commands.addCommands(new CommandData("ticket", "Manage tickets.").addSubcommands(new SubcommandData("add", "Add a member to a ticket.").addOptions(new OptionData(OptionType.USER, "member", "Member to add.", true)), new SubcommandData("remove", "Remove a member from a ticket.").addOptions(new OptionData(OptionType.USER, "member", "Member to remove.", true)), new SubcommandData("transcript", "Force make a ticket transcript."), new SubcommandData("close", "Close a ticket.").addOptions(new OptionData(OptionType.STRING, "reason", "Reason to close the ticket. (Optional)")))).queue(cmds -> {
cmds.forEach(command -> {
CommandPrivilege[] privilege = cmdModules.stream().filter(c -> c.getName().equals(command.getName())).map(CommandModule::getCommandPrivileges).findFirst().orElse(new CommandPrivilege[] {});
if (privilege.length > 0)
TechDiscordBot.getGuild().updateCommandPrivilegesById(command.getId(), Arrays.asList(privilege)).queue();
});
});
TechDiscordBot.getJDA().addEventListener(modules.toArray());
TechDiscordBot.getJDA().addEventListener(cmdModules.toArray());
Runtime.getRuntime().addShutdownHook(new Thread(() -> modules.forEach(Module::onDisable)));
}
Aggregations