use of net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction in project Bean by Xirado.
the class InteractionCommandHandler method updateCommands.
public void updateCommands(Consumer<List<Command>> success, Consumer<Throwable> failure) {
if (!Bean.getInstance().isDebug()) {
commandUpdateAction.queue(success, failure);
for (Map.Entry<Long, List<GenericCommand>> entrySet : registeredGuildCommands.entrySet()) {
Long guildID = entrySet.getKey();
List<GenericCommand> slashCommands = entrySet.getValue();
if (guildID == null || slashCommands == null)
continue;
if (slashCommands.isEmpty())
continue;
Guild guild = Bean.getInstance().getShardManager().getGuildById(guildID);
if (guild == null)
continue;
CommandListUpdateAction guildCommandUpdateAction = guild.updateCommands();
for (GenericCommand cmd : slashCommands) {
guildCommandUpdateAction = guildCommandUpdateAction.addCommands(cmd.getData());
}
if (slashCommands.size() > 0)
guildCommandUpdateAction.queue();
}
} else {
List<GenericCommand> commands = registeredGuildCommands.get(Bean.TEST_SERVER_ID);
if (commands != null && !commands.isEmpty()) {
Guild guild = Bean.getInstance().getShardManager().getGuildById(Bean.TEST_SERVER_ID);
if (guild == null)
return;
CommandListUpdateAction commandListUpdateAction = guild.updateCommands();
for (GenericCommand cmd : commands) commandListUpdateAction.addCommands(cmd.getData());
commandListUpdateAction.queue(success, failure);
}
}
}
use of net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction in project HangmanDiscordBot by megoRU.
the class BotStartConfig method updateSlashCommands.
private void updateSlashCommands(boolean isUpdateInGuilds) {
try {
if (isUpdateInGuilds) {
for (int i = 0; i < jda.getGuilds().size(); i++) {
jda.getGuilds().get(i).updateCommands().queue();
}
} else {
CommandListUpdateAction commands = jda.updateCommands();
List<OptionData> options = new ArrayList<>();
options.add(new OptionData(STRING, "game", "Setting the Game language").addChoice("eng", "eng").addChoice("rus", "rus").setRequired(true));
options.add(new OptionData(STRING, "bot", "Setting the bot language").addChoice("eng", "eng").addChoice("rus", "rus").setRequired(true));
commands.addCommands(Commands.slash("language", "Setting language").addOptions(options));
commands.addCommands(Commands.slash("hg", "Start the game"));
commands.addCommands(Commands.slash("stop", "Stop the game"));
commands.addCommands(Commands.slash("help", "Bot commands"));
commands.addCommands(Commands.slash("stats", "Get your statistics"));
commands.addCommands(Commands.slash("mystats", "Find out the number of your wins and losses"));
commands.addCommands(Commands.slash("allstats", "Find out the statistics of all the bot's games"));
commands.addCommands(Commands.slash("delete", "Deleting your data"));
commands.queue();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction in project Ree6 by Ree6-Applications.
the class CommandManager method addSlashCommand.
/**
* Method used to add all Commands as SlashCommand on Discord.
*/
public void addSlashCommand() {
CommandListUpdateAction listUpdateAction = BotInfo.botInstance.updateCommands();
for (Command command : getCommands()) {
if (command.getCategory() == Category.HIDDEN || command.getCommandData() == null)
continue;
// noinspection ResultOfMethodCallIgnored
listUpdateAction.addCommands(command.getCommandData());
}
listUpdateAction.queue();
}
use of net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction 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;
}
use of net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction in project BotCommands by freya022.
the class ApplicationCommandsUpdater method updateCommands.
@Blocking
public void updateCommands() {
final CommandListUpdateAction updateAction = guild != null ? guild.updateCommands() : context.getJDA().updateCommands();
final List<Command> commands = updateAction.addCommands(allCommandData).complete();
updatedCommands = true;
if (guild != null) {
thenAcceptGuild(commands, guild);
} else {
thenAcceptGlobal(commands);
}
}
Aggregations