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

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

add shoot command
Marco Andronaco andronacomarco@gmail.com
Fri, 19 Jan 2024 11:06:13 +0100
commit

212dbc349e9c614822b8877c19ca95faa85d7349

parent

34d90ffd27e2def867cb627ae49aad8e3431fde3

2 files changed, 25 insertions(+), 1 deletions(-)

jump to
A src/commands/shoot.ts

@@ -0,0 +1,24 @@

+import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js'; +import { getChannel } from '../functions/music'; + +module.exports = { + data: new SlashCommandBuilder() + .setName('shoot') + .setDescription('Kick a random member of your voice channel.'), + + async execute(interaction: ChatInputCommandInteraction) { + const channel = await getChannel(interaction); + if (typeof channel == 'string') + return await interaction.reply({ content: channel, ephemeral: true }); + + const voiceChannelUsers = interaction.guild.voiceStates.cache.filter( + (voiceState) => voiceState.channelId === channel.id + ); + const members = voiceChannelUsers.map((voiceState) => voiceState.member); + const randomIndex = Math.floor(Math.random() * members.length); + const toBeKicked = members[randomIndex]; + toBeKicked.voice.disconnect(); + + return await interaction.reply({ content: `💥 Bang! **${toBeKicked.user.globalName}** was shot.` }); + }, +};
M src/commands/stop.tssrc/commands/stop.ts

@@ -14,7 +14,7 @@

const queue = getQueue(interaction.guildId); const r = queue.stop(); if (r) - return await interaction.reply({ content: 'Stopped.', ephemeral: true }); + return await interaction.reply({ content: 'Stopped.' }); return await interaction.reply({ content: 'Error.', ephemeral: true }); },