use of net.dv8tion.jda.api.interactions.commands.build.CommandData in project DIH4JDA by DynxstyGIT.
the class InteractionHandler method getGuildContextCommandData.
/**
* Gets all Guild Context commands registered in {@link InteractionHandler#registerContextCommands()} and
* returns their {@link CommandData} as a List.
*
* @param guild The context command's guild.
* @throws Exception If an error occurs.
*/
private Set<CommandData> getGuildContextCommandData(@NotNull Guild guild) throws Exception {
Set<CommandData> commands = new HashSet<>();
for (Class<? extends BaseContextCommand> contextCommandClass : this.guildContexts) {
BaseContextCommand instance = (BaseContextCommand) this.getClassInstance(guild, contextCommandClass);
commands.add(this.getContextCommandData(instance, contextCommandClass));
}
DIH4JDALogger.info(String.format("[%s] Queuing Guild Context Commands", guild.getName()), DIH4JDALogger.Type.CONTEXT_COMMANDS_QUEUED);
return commands;
}
use of net.dv8tion.jda.api.interactions.commands.build.CommandData in project cds by iamysko.
the class AppConfig method jda.
/**
* Jda.
*
* @param discordUpListener the discord up listener
* @param discordDownListener the discord down listener
* @param reactionListener the reaction listener
* @param messageListener the message listener
* @param updateRoleListener the role Listener
* @param slashCommandListener the slashCommand Listener
* @param buttonClickListener the buttonClick Listener
* @param jdaToken the jda token
* @return the jda
*/
@Bean
JDA jda(@Qualifier("discordUpListener") final DiscordUpListener discordUpListener, @Qualifier("discordDownListener") final DiscordDownListener discordDownListener, @Qualifier("reactionListener") final ReactionListener reactionListener, @Qualifier("messageListener") final MessageListener messageListener, @Qualifier("slashCommandListener") final SlashCommandListener slashCommandListener, @Qualifier("buttonClickListener") final ButtonClickListener buttonClickListener, @Qualifier("updateRoleListener") final UpdateRoleListener updateRoleListener, @Value("${jda.token}") final String jdaToken) {
final JDABuilder builder = JDABuilder.createDefault(jdaToken);
builder.addEventListeners(discordUpListener, discordDownListener, reactionListener, messageListener, slashCommandListener, buttonClickListener, updateRoleListener);
builder.setActivity(Activity.watching("the Roblox Discord"));
builder.enableIntents(GatewayIntent.GUILD_MEMBERS);
builder.setMemberCachePolicy(MemberCachePolicy.ALL);
builder.disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS, CacheFlag.VOICE_STATE, CacheFlag.MEMBER_OVERRIDES);
builder.setChunkingFilter(ChunkingFilter.NONE);
builder.disableIntents(GatewayIntent.GUILD_PRESENCES, GatewayIntent.GUILD_MESSAGE_TYPING);
builder.setLargeThreshold(50);
try {
final JDA jda = builder.build();
jda.awaitReady();
jda.getGuildById(Properties.GUILD_ROBLOX_DISCORD_ID).updateCommands().addCommands(new CommandData(SlashCommandConstants.COMMAND_HELP, "Shows all current commands")).addCommands(new CommandData(SlashCommandConstants.COMMAND_ABOUT, "About the bot")).addCommands(new CommandData(SlashCommandConstants.COMMAND_USER_INFO, "Shows information about the user").addOption(OptionType.USER, "user", "The user to see the info", true)).addCommands(new CommandData(SlashCommandConstants.COMMAND_ROBLOX_USER_INFO, "Shows information about the Roblox user").addOption(OptionType.STRING, "username", "The username to see the info", true)).queue();
return jda;
} catch (final LoginException e) {
TelegramService.sendToTelegram(Instant.now(), TelegramService.ERROR_UNKNOWN);
} catch (final InterruptedException e) {
TelegramService.sendToTelegram(Instant.now(), TelegramService.ERROR_WAIT_JDA);
}
return null;
}
use of net.dv8tion.jda.api.interactions.commands.build.CommandData in project Discord-Core-Bot-Apple by demodude4u.
the class DiscordBot method buildUpdateCommands.
// Hold my beer
@SuppressWarnings("unchecked")
private void buildUpdateCommands(CommandListUpdateAction updateCommands) {
Map<String, Object> root = new LinkedHashMap<>();
for (SlashCommandDefinition command : commandSlash.values()) {
String[] pathSplit = command.getPath().split("/");
Map<String, Object> group = root;
for (int i = 0; i < pathSplit.length; i++) {
String name = pathSplit[i];
if (i == pathSplit.length - 1) {
group.put(name, command);
} else {
Object subGroup = group.get(name);
if (subGroup == null) {
group.put(name, subGroup = new LinkedHashMap<String, Object>());
}
group = (Map<String, Object>) subGroup;
}
}
}
for (Entry<String, Object> rootEntry : root.entrySet()) {
SlashCommandData commandData;
if (rootEntry.getValue() instanceof SlashCommandDefinition) {
SlashCommandDefinition commandDefinition = (SlashCommandDefinition) rootEntry.getValue();
commandData = Commands.slash(rootEntry.getKey(), commandDefinition.getDescription());
for (SlashCommandOptionDefinition option : commandDefinition.getOptions()) {
commandData = commandData.addOption(option.getType(), option.getName(), option.getDescription(), option.isRequired(), option.isAutoComplete());
}
} else {
Map<String, Object> sub = (Map<String, Object>) rootEntry.getValue();
commandData = Commands.slash(rootEntry.getKey(), sub.keySet().stream().collect(Collectors.joining(", ")));
for (Entry<String, Object> subEntry : sub.entrySet()) {
if (subEntry.getValue() instanceof SlashCommandDefinition) {
SlashCommandDefinition commandDefinition = (SlashCommandDefinition) subEntry.getValue();
SubcommandData subcommandData = new SubcommandData(subEntry.getKey(), commandDefinition.getDescription());
for (SlashCommandOptionDefinition option : commandDefinition.getOptions()) {
subcommandData = subcommandData.addOption(option.getType(), option.getName(), option.getDescription(), option.isRequired(), option.isAutoComplete());
}
commandData = commandData.addSubcommands(subcommandData);
} else {
Map<String, SlashCommandDefinition> subSub = (Map<String, SlashCommandDefinition>) subEntry.getValue();
SubcommandGroupData subcommandGroupData = new SubcommandGroupData(subEntry.getKey(), subSub.keySet().stream().collect(Collectors.joining(", ")));
for (Entry<String, SlashCommandDefinition> subSubEntry : subSub.entrySet()) {
SubcommandData subcommandData = new SubcommandData(subSubEntry.getKey(), subSubEntry.getValue().getDescription());
for (SlashCommandOptionDefinition option : subSubEntry.getValue().getOptions()) {
subcommandData = subcommandData.addOption(option.getType(), option.getName(), option.getDescription(), option.isRequired(), option.isAutoComplete());
}
subcommandGroupData = subcommandGroupData.addSubcommands(subcommandData);
}
commandData = commandData.addSubcommandGroups(subcommandGroupData);
}
}
}
updateCommands = updateCommands.addCommands(commandData);
}
for (MessageCommandDefinition commandDefinition : commandMessage.values()) {
CommandData commandData = Commands.message(commandDefinition.getName());
updateCommands = updateCommands.addCommands(commandData);
}
}
use of net.dv8tion.jda.api.interactions.commands.build.CommandData in project TAS-Battle by MCPfannkuchenYT.
the class TASDiscordBot method run.
@Override
public void run() {
for (Guild g : jda.getGuilds()) {
CommandListUpdateAction updater = g.updateCommands();
updater.addCommands(new CommandData("play", "Show other players that you are ready to play!"));
updater.addCommands(new CommandData("online", "Show all players that are online on the server"));
updater.addCommands(new CommandData("link", "Link your Discord account to your Minecraft Account"));
updater.queue();
}
recreateMessage();
}
use of net.dv8tion.jda.api.interactions.commands.build.CommandData in project TechDiscordBot by TechsCode-Team.
the class ModulesManager method load.
public void load() {
TechDiscordBot.getJDA().updateCommands().queue();
CommandListUpdateAction commands = TechDiscordBot.getGuild().updateCommands();
for (Class<?> each : ProjectUtil.getClasses("me.TechsCode.TechDiscordBot.module")) {
if (CommandModule.class.isAssignableFrom(each) && !Modifier.isAbstract(each.getModifiers())) {
try {
CommandModule module = (CommandModule) each.getConstructor(TechDiscordBot.class).newInstance(TechDiscordBot.getBot());
if (module.getName() == null)
continue;
cmdModules.add(module);
CommandData cmdData = new CommandData(module.getName(), module.getDescription() == null ? "No description set." : module.getDescription()).addOptions(module.getOptions()).setDefaultEnabled(module.getCommandPrivileges().length == 0);
commands.addCommands(cmdData);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
} else if (Module.class.isAssignableFrom(each) && !Modifier.isAbstract(each.getModifiers())) {
try {
Module module = (Module) each.getConstructor(TechDiscordBot.class).newInstance(TechDiscordBot.getBot());
module.enable();
modules.add(module);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
}
commands.addCommands(new CommandData("ticket", "Manage tickets.").addSubcommands(new SubcommandData("add", "Add a member to a ticket.").addOptions(new OptionData(OptionType.USER, "member", "Member to add.", true)), new SubcommandData("remove", "Remove a member from a ticket.").addOptions(new OptionData(OptionType.USER, "member", "Member to remove.", true)), new SubcommandData("transcript", "Force make a ticket transcript."), new SubcommandData("close", "Close a ticket.").addOptions(new OptionData(OptionType.STRING, "reason", "Reason to close the ticket. (Optional)")))).queue(cmds -> {
cmds.forEach(command -> {
CommandPrivilege[] privilege = cmdModules.stream().filter(c -> c.getName().equals(command.getName())).map(CommandModule::getCommandPrivileges).findFirst().orElse(new CommandPrivilege[] {});
if (privilege.length > 0)
TechDiscordBot.getGuild().updateCommandPrivilegesById(command.getId(), Arrays.asList(privilege)).queue();
});
});
TechDiscordBot.getJDA().addEventListener(modules.toArray());
TechDiscordBot.getJDA().addEventListener(cmdModules.toArray());
Runtime.getRuntime().addShutdownHook(new Thread(() -> modules.forEach(Module::onDisable)));
}
Aggregations