@@ -20,11 +20,18 @@ package me.duncte123.skybot.commands.mod
2020
2121import me.duncte123.botcommons.messaging.MessageUtils.sendMsg
2222import me.duncte123.botcommons.messaging.MessageUtils.sendSuccess
23+ import me.duncte123.skybot.Variables
2324import me.duncte123.skybot.commands.guild.mod.ModBaseCommand
2425import me.duncte123.skybot.objects.command.CommandContext
26+ import me.duncte123.skybot.objects.command.ISlashCommand
2527import net.dv8tion.jda.api.Permission
28+ import net.dv8tion.jda.api.entities.channel.ChannelType
29+ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
30+ import net.dv8tion.jda.api.interactions.commands.OptionType
31+ import net.dv8tion.jda.api.interactions.commands.build.OptionData
32+ import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData
2633
27- class VoiceKickCommand : ModBaseCommand () {
34+ class VoiceKickCommand : ModBaseCommand (), ISlashCommand {
2835 init {
2936 this .requiresArgs = true
3037 this .name = " voicekick"
@@ -68,4 +75,70 @@ class VoiceKickCommand : ModBaseCommand() {
6875
6976 sendMsg(ctx, " I could not find any Voice Channel or member to kick from voice" )
7077 }
78+
79+ override fun getDescription (): String = this .help
80+
81+ override fun getSlashData (): SlashCommandData {
82+ return super .getSlashData()
83+ .addOptions(
84+ OptionData (
85+ OptionType .CHANNEL ,
86+ " voice_channel" ,
87+ " The voice channel to kick ALL users from." ,
88+ false
89+ ),
90+ OptionData (
91+ OptionType .USER ,
92+ " user" ,
93+ " The user to kick from the voice channel they are currently in." ,
94+ false
95+ ),
96+ )
97+ }
98+
99+ override fun handleSlashEvent (event : SlashCommandInteractionEvent , variables : Variables ) {
100+ val vc = event.getOption(" voice_channel" )?.asChannel
101+
102+ if (vc != null ) {
103+ if (vc.type == ChannelType .VOICE ) {
104+ event.reply(" Kicking all users from `${vc.name} `, please wait..." )
105+ .setEphemeral(false )
106+ .queue()
107+
108+ vc.asVoiceChannel().createCopy().queue {
109+ vc.delete().reason(" Kicking all users from voice (${event.user.asTag} )" ).queue()
110+
111+ event.hook.editOriginal(" Kicked all users from `${vc.name} `" ).queue()
112+ }
113+ return
114+ }
115+
116+ event.reply(" Can't voice kick from a text channel, sorry" )
117+ .setEphemeral(true )
118+ .queue()
119+ return
120+ }
121+
122+ val member = event.getOption(" user" )?.asMember
123+
124+ if (member != null ) {
125+ val memberChannel = member.voiceState?.channel
126+
127+ // We have to "== true" here because the return type is a nullable boolean
128+ if (member.voiceState?.inAudioChannel() == true ) {
129+ event.guild!! .kickVoiceMember(member).queue()
130+ event.reply(" Kicked ${member.user.asTag} from voice" ).setEphemeral(false ).queue()
131+ return
132+ }
133+
134+ event.reply(" That user is not in a voice channel" )
135+ .setEphemeral(true )
136+ .queue()
137+
138+ return
139+ }
140+
141+ event.reply(" Please either specify a voice channel or a user to kick from the voice channel." )
142+ .queue()
143+ }
71144}
0 commit comments