From e17c8a08c255e0455ddb6be67e53c83907722e80 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 28 Jun 2024 19:07:01 +0100 Subject: [PATCH] fix for sub commands since discord doesn't allow not showing them in dms --- .../java/cc/fascinated/bat/service/CommandService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/cc/fascinated/bat/service/CommandService.java b/src/main/java/cc/fascinated/bat/service/CommandService.java index c54ba1d..d01240f 100644 --- a/src/main/java/cc/fascinated/bat/service/CommandService.java +++ b/src/main/java/cc/fascinated/bat/service/CommandService.java @@ -150,6 +150,7 @@ public class CommandService extends ListenerAdapter { try { BatCommandExecutor executor = null; List requiredPermissions = new ArrayList<>(); + boolean isSubCommand = false; // No args provided, use the main command executor if (event.getInteraction().getSubcommandName() == null) { @@ -162,6 +163,7 @@ public class CommandService extends ListenerAdapter { executor = subCommand.getValue(); requiredPermissions.addAll(Arrays.asList(subCommand.getValue().getCommandInfo().requiredPermissions())); requiredPermissions.addAll(Arrays.asList(command.getCommandInfo().requiredPermissions())); // not sure if we'd want this, but it's here for now + isSubCommand = true; break; } } @@ -196,6 +198,14 @@ public class CommandService extends ListenerAdapter { return; } } + + if (isSubCommand && command.getCommandInfo().guildOnly() && !ranInsideGuild) { + event.replyEmbeds(EmbedUtils.errorEmbed() + .setDescription("This command can only be executed in a guild") + .build()).setEphemeral(true).queue(); + return; + } + log.info("Executing command \"{}\" for user \"{}\"", commandName, user.getDiscordUser().getName()); executor.execute(guild, user, ranInsideGuild ? event.getChannel().asTextChannel() : event.getChannel().asPrivateChannel(), event.getMember(), event.getInteraction());