From 32102cac3bd8775b1033200ccfde5bf07a9b2ff8 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Mon, 11 Apr 2022 03:29:59 +0200 Subject: [PATCH] Switched to using CommandData in registerCommand and allow USER commands to work in guilds --- src/main/java/com/alttd/util/Util.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/alttd/util/Util.java b/src/main/java/com/alttd/util/Util.java index 3576c07..6d61515 100644 --- a/src/main/java/com/alttd/util/Util.java +++ b/src/main/java/com/alttd/util/Util.java @@ -11,7 +11,7 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; -import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; +import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.requests.RestAction; import org.jetbrains.annotations.NotNull; @@ -96,20 +96,19 @@ public class Util { .build(); } - public static void registerCommand(CommandManager commandManager, JDA jda, SlashCommandData slashCommandData, String commandName) { + public static void registerCommand(CommandManager commandManager, JDA jda, CommandData commandData, String commandName) { for (ScopeInfo info : commandManager.getActiveLocations(commandName)) { switch (info.getScope()) { - case GLOBAL -> jda.updateCommands().addCommands(slashCommandData).queue(); - case GUILD -> { + case GLOBAL -> jda.updateCommands().addCommands(commandData).queue(); + case GUILD, USER -> { Guild guildById = jda.getGuildById(info.getId()); if (guildById == null) { Logger.warning("Tried to add command % to invalid guild %.", commandName, String.valueOf(info.getId())); continue; } - guildById.updateCommands().addCommands(slashCommandData).queue(RestAction.getDefaultSuccess(), Util::handleFailure); + guildById.updateCommands().addCommands(commandData).queue(RestAction.getDefaultSuccess(), Util::handleFailure); } - case USER -> Logger.warning("Tried to add command % to user, this is not implemented yet since I don't know how this should work."); } } }