use of net.dv8tion.jda.api.interactions.commands.Command in project BotCommands by freya022.
the class ApplicationCommandsUpdater method computeContextCommands.
@SuppressWarnings("unchecked")
private <T extends ApplicationCommandInfo> void computeContextCommands(List<ApplicationCommandInfo> guildApplicationCommands, Class<T> targetClazz, Command.Type type) {
guildApplicationCommands.stream().filter(a -> targetClazz.isAssignableFrom(a.getClass())).map(a -> (T) a).distinct().forEachOrdered(info -> {
final CommandPath notLocalizedPath = info.getPath();
try {
final LocalizedCommandData localizedCommandData = LocalizedCommandData.of(context, guild, info);
localizedBaseNameToBaseName.put(localizedCommandData.getLocalizedPath().getName(), notLocalizedPath.getName());
// User command name
final CommandPath localizedPath = localizedCommandData.getLocalizedPath();
Checks.check(localizedPath.getNameCount() == notLocalizedPath.getNameCount(), "Localized path does not have the same name count as the not-localized path");
final boolean isDefaultEnabled = isDefaultEnabled(info);
if (localizedPath.getNameCount() == 1) {
// Standard command
final CommandData rightCommand = Commands.context(type, localizedPath.getName());
map.put(type, localizedPath, rightCommand);
rightCommand.setDefaultEnabled(isDefaultEnabled);
if (info.isOwnerRequired()) {
// Must be non-localized name
ownerOnlyCommands.add(notLocalizedPath.getName());
}
} else {
throw new IllegalStateException("A " + type.name() + " command with more than 1 path component got registered");
}
context.addApplicationCommandAlternative(localizedPath, type, info);
} catch (Exception e) {
throw new RuntimeException("An exception occurred while processing a " + type.name() + " command " + notLocalizedPath, e);
}
});
}
use of net.dv8tion.jda.api.interactions.commands.Command in project SqueethDiscordBot by AlphaSerpentis.
the class About method addCommand.
@Override
public void addCommand(JDA jda) {
Command cmd = jda.upsertCommand(name, description).complete();
commandId = cmd.getIdLong();
}
use of net.dv8tion.jda.api.interactions.commands.Command in project SqueethDiscordBot by AlphaSerpentis.
the class Funding method addCommand.
@Override
public void addCommand(JDA jda) {
Command cmd = jda.upsertCommand(name, description).addOption(OptionType.NUMBER, "amount", "The amount of oSQTH in USD you have", true).addOption(OptionType.INTEGER, "days", "The amount of days you will maintain this position", true).addOption(OptionType.NUMBER, "funding", "The funding rate in %", false).complete();
commandId = cmd.getIdLong();
}
use of net.dv8tion.jda.api.interactions.commands.Command in project Essentials by EssentialsX.
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);
});
}
}
use of net.dv8tion.jda.api.interactions.commands.Command 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