all repos — simple-discord-music-bot @ 212dbc349e9c614822b8877c19ca95faa85d7349

A Discord bot making use of discord.js and play-yt.

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 randomIndex = Math.floor(Math.random() * members.length);
19        const toBeKicked = members[randomIndex];
20        toBeKicked.voice.disconnect();
21
22        return await interaction.reply({ content: `💥 Bang! **${toBeKicked.user.globalName}** was shot.` });
23    },
24};