use of net.essentialsx.api.v2.services.discord.InteractionCommand in project Essentials by drtshock.
the class InteractionControllerImpl method processBatchRegistration.
public void processBatchRegistration() {
if (!initialBatchRegistration && !batchRegistrationQueue.isEmpty()) {
initialBatchRegistration = true;
final List<CommandData> list = new ArrayList<>();
for (final InteractionCommand command : batchRegistrationQueue.values()) {
final CommandData data = new CommandData(command.getName(), command.getDescription());
if (command.getArguments() != null) {
for (final InteractionCommandArgument argument : command.getArguments()) {
data.addOption(OptionType.valueOf(argument.getType().name()), argument.getName(), argument.getDescription(), argument.isRequired());
}
}
list.add(data);
}
jda.getGuild().updateCommands().addCommands(list).queue(success -> {
for (final Command command : success) {
commandMap.put(command.getName(), batchRegistrationQueue.get(command.getName()));
batchRegistrationQueue.remove(command.getName());
if (jda.isDebug()) {
logger.info("Registered guild command " + command.getName() + " with id " + command.getId());
}
}
if (!batchRegistrationQueue.isEmpty()) {
logger.warning(batchRegistrationQueue.size() + " Discord commands were lost during command registration!");
if (jda.isDebug()) {
logger.warning("Lost commands: " + batchRegistrationQueue.keySet());
}
batchRegistrationQueue.clear();
}
}, failure -> {
if (failure instanceof ErrorResponseException && ((ErrorResponseException) failure).getErrorResponse() == ErrorResponse.MISSING_ACCESS) {
logger.severe(tl("discordErrorCommand"));
return;
}
logger.log(Level.SEVERE, "Error while registering command", failure);
});
}
}
Aggregations