Skip to content

Commit

Permalink
feat: don't allow multiple voice channels to be created if a user alr…
Browse files Browse the repository at this point in the history
…eady has a voice channel
  • Loading branch information
joshbker committed Feb 17, 2024
1 parent 6b6347d commit a0177d2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/kotlin/com/learnspigot/bot/voicechat/VCCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit a0177d2

Please sign in to comment.