src/commands/shoot.ts (view raw)
1import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js';
2import { getChannel } from '../functions/music';
3
4module.exports = {
5 data: new SlashCommandBuilder()
6 .setName('shoot')
7 .setDescription('Kick a random member of your voice channel.'),
8
9 async execute(interaction: ChatInputCommandInteraction) {
10 const channel = await getChannel(interaction);
11 if (typeof channel == 'string')
12 return await interaction.reply({ content: channel, ephemeral: true });
13
14 const voiceChannelUsers = interaction.guild.voiceStates.cache.filter(
15 (voiceState) => voiceState.channelId === channel.id
16 );
17 const members = voiceChannelUsers.map((voiceState) => voiceState.member);
18 const l = members.length
19 const randomIndex = Math.floor(Math.random() * l);
20 const toBeKicked = members[randomIndex].user.bot ? members[(randomIndex + 1) % l] : members[randomIndex];
21
22 toBeKicked.voice.disconnect();
23 const victimName = toBeKicked.nickname ?? toBeKicked.user.globalName;
24 return await interaction.reply({ content: `💥 Bang! **${victimName}** was shot.` });
25 },
26};