From a0177d2e48ed533b55d494c41eaa188d63709c96 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Sat, 17 Feb 2024 20:42:07 +0000 Subject: [PATCH] feat: don't allow multiple voice channels to be created if a user already has a voice channel --- .../com/learnspigot/bot/voicechat/VCCommand.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/learnspigot/bot/voicechat/VCCommand.kt b/src/main/kotlin/com/learnspigot/bot/voicechat/VCCommand.kt index 17bdee6..7d1b4f1 100644 --- a/src/main/kotlin/com/learnspigot/bot/voicechat/VCCommand.kt +++ b/src/main/kotlin/com/learnspigot/bot/voicechat/VCCommand.kt @@ -24,23 +24,30 @@ class VCCommand { event: SlashCommandInteractionEvent, @Description("Max user limit") @Optional limit: Int?, ) { + val guild = event.guild ?: return + val member = event.member ?: return + + if (guild.getVoiceChannelsByName("${member.effectiveName}'s channel", true).isNotEmpty()) { + event.reply("You already have a voice channel!").setEphemeral(true).queue() + return + } + if (limit != null && limit < 1) { event.reply("The max user limit must be 1 or higher.").setEphemeral(true).queue() return } - val guild = event.guild ?: return val newChannel = guild.createVoiceChannel( - "${event.member!!.effectiveName}'s channel", - event.guild!!.getCategoryById(Environment.get("CHAT_CATEGORY")) + "${member.effectiveName}'s channel", + guild.getCategoryById(Environment.get("CHAT_CATEGORY")) ).complete() if (limit != null) { newChannel.manager.setUserLimit(limit).queue() } - if (event.member!!.voiceState?.inAudioChannel() == true) - guild.moveVoiceMember(event.member!!, newChannel).queue() + if (member.voiceState?.inAudioChannel() == true) + guild.moveVoiceMember(member, newChannel).queue() event.reply("Your voice channel has been created - ${newChannel.asMention}").setEphemeral(true).queue()