use of net.dv8tion.jda.api.interactions.commands.build.Commands in project JDA by DV8FromTheWorld.
the class CommandListUpdateActionImpl method addCommands.
@Nonnull
@Override
public CommandListUpdateAction addCommands(@Nonnull Collection<? extends CommandData> commands) {
Checks.noneNull(commands, "Command");
int newSlash = 0, newUser = 0, newMessage = 0;
for (CommandData command : commands) {
switch(command.getType()) {
case SLASH:
newSlash++;
break;
case MESSAGE:
newMessage++;
break;
case USER:
newUser++;
break;
}
}
Checks.check(slash + newSlash <= Commands.MAX_SLASH_COMMANDS, "Cannot have more than %d slash commands! Try using subcommands instead.", Commands.MAX_SLASH_COMMANDS);
Checks.check(user + newUser <= Commands.MAX_USER_COMMANDS, "Cannot have more than %d user context commands!", Commands.MAX_USER_COMMANDS);
Checks.check(message + newMessage <= Commands.MAX_MESSAGE_COMMANDS, "Cannot have more than %d message context commands!", Commands.MAX_MESSAGE_COMMANDS);
Checks.checkUnique(Stream.concat(commands.stream(), this.commands.stream()).map(c -> c.getType() + " " + c.getName()), "Cannot have multiple commands of the same type with identical names. " + "Name: \"%s\" with type %s appeared %d times!", (count, value) -> {
String[] tuple = value.split(" ", 2);
return new Object[] { tuple[1], tuple[0], count };
});
slash += newSlash;
user += newUser;
message += newMessage;
this.commands.addAll(commands);
return this;
}
Aggregations