use of com.freya02.botcommands.internal.prefixed.CommandListener 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();
}
Aggregations