fix for sub commands since discord doesn't allow not showing them in dms

This commit is contained in:
Lee 2024-06-28 19:07:01 +01:00
parent fa205d7ff2
commit e17c8a08c2

View File

@ -150,6 +150,7 @@ public class CommandService extends ListenerAdapter {
try {
BatCommandExecutor executor = null;
List<Permission> 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());