use of com.freya02.botcommands.api.CommandsBuilder in project BotCommands by freya022.
the class CommandsBuilderImpl method build.
/**
* Builds the command listener and automatically registers all listener to the JDA instance
*
* @param jda The JDA instance of your bot
*/
public void build(JDA jda) throws Exception {
if (jda.getShardInfo().getShardId() != 0) {
LOGGER.warn("A shard other than 0 was passed to CommandsBuilder#build, shard 0 is needed to handle DMing exceptions, manually retrieving shard 0...");
final ShardManager manager = jda.getShardManager();
if (manager == null)
throw new IllegalArgumentException("Unable to retrieve Shard 0 as shard manager is null");
jda = manager.getShardById(0);
if (jda == null)
throw new IllegalArgumentException("Unable to retrieve Shard 0");
}
if (jda.getStatus() != JDA.Status.CONNECTED) {
try {
LOGGER.warn("JDA should already be ready when you call #build on CommandsBuilder !");
jda.awaitReady();
} catch (InterruptedException e) {
throw new RuntimeException("CommandsBuilder got interrupted while waiting for JDA to be ready", e);
}
}
final List<GatewayIntent> intents = List.of(GatewayIntent.GUILD_MESSAGES);
if (!jda.getGatewayIntents().containsAll(intents)) {
throw new IllegalStateException("JDA must have these intents enabled: " + intents.stream().map(Enum::name).collect(Collectors.joining(", ")));
}
setupContext(jda);
ReflectionUtils.scanAnnotations(classes);
buildClasses();
context.addEventListeners(new EventWaiter(jda), new CommandListener(context), new ApplicationUpdaterListener(context), new ApplicationCommandListener(context));
if (!ignoredClasses.isEmpty()) {
LOGGER.trace("Ignored classes in search paths:");
for (Class<?> ignoredClass : ignoredClasses) {
LOGGER.trace("\t{}", ignoredClass.getName());
}
}
ConflictDetector.detectConflicts();
}
use of com.freya02.botcommands.api.CommandsBuilder in project BotCommands by freya022.
the class SlashMain method main.
public static void main(String[] args) {
try {
final Config config = Config.readConfig();
final JDA jda = JDABuilder.createLight(config.getToken()).build().awaitReady();
final CommandsBuilder builder = CommandsBuilder.newBuilder();
builder.setSettingsProvider(new BasicSettingsProvider(builder.getContext())).build(jda, "com.freya02.bot.wiki.slash.commands");
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
Aggregations