From df47c7a70904495fb905db644cf0561a959c409f Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Wed, 19 Oct 2022 03:13:02 +0200 Subject: [PATCH] Improved channel type check --- .../commands/CommandSetOutputChannel.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/alttd/commandManager/commands/CommandSetOutputChannel.java b/src/main/java/com/alttd/commandManager/commands/CommandSetOutputChannel.java index a0220a5..408869b 100644 --- a/src/main/java/com/alttd/commandManager/commands/CommandSetOutputChannel.java +++ b/src/main/java/com/alttd/commandManager/commands/CommandSetOutputChannel.java @@ -73,21 +73,20 @@ public class CommandSetOutputChannel extends DiscordCommand { } ChannelType channelType = option.getChannelType(); - switch (channelType) { - case TEXT, NEWS, GUILD_NEWS_THREAD, GUILD_PUBLIC_THREAD, GUILD_PRIVATE_THREAD, FORUM -> { - GuildChannelUnion channel = option.getAsChannel(); - boolean success = CommandOutputChannels.setOutputChannel(guild.getIdLong(), outputType, channel.getIdLong(), channelType); - if (success) - event.replyEmbeds(Util.genericSuccessEmbed("Success", "Set channel " + channel.getAsMention() + " as the output channel for " + outputType.name() + ".")) - .setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure); - else - event.replyEmbeds(Util.genericErrorEmbed("Error", "Unable to store the new channel output in the database")) - .setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure); - } - default -> event.replyEmbeds(Util.genericErrorEmbed("Error", "The channel type " + channelType.name() + " is not a valid output channel type")) + if (channelType.isMessage() || channelType.isThread()) { + GuildChannelUnion channel = option.getAsChannel(); + boolean success = CommandOutputChannels.setOutputChannel(guild.getIdLong(), outputType, channel.getIdLong(), channelType); + if (success) + event.replyEmbeds(Util.genericSuccessEmbed("Success", "Set channel " + channel.getAsMention() + " as the output channel for " + outputType.name() + ".")) + .setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure); + else + event.replyEmbeds(Util.genericErrorEmbed("Error", "Unable to store the new channel output in the database")) + .setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure); + } + else { + event.replyEmbeds(Util.genericErrorEmbed("Error", "The channel type " + channelType.name() + " is not a valid output channel type")) .setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure); } - } @Override