all repos — simple-discord-music-bot @ 7bceff48000d0f7b54cf9d779ec1ea4c931289c5

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

avoid bots being kicked by /shoot
Marco Andronaco andronacomarco@gmail.com
Sun, 21 Jan 2024 11:17:46 +0100
commit

7bceff48000d0f7b54cf9d779ec1ea4c931289c5

parent

212dbc349e9c614822b8877c19ca95faa85d7349

1 files changed, 6 insertions(+), 4 deletions(-)

jump to
M src/commands/shoot.tssrc/commands/shoot.ts

@@ -15,10 +15,12 @@ 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(); + const l = members.length + const randomIndex = Math.floor(Math.random() * l); + const toBeKicked = members[randomIndex].user.bot ? members[(randomIndex + 1) % l] : members[randomIndex]; - return await interaction.reply({ content: `💥 Bang! **${toBeKicked.user.globalName}** was shot.` }); + toBeKicked.voice.disconnect(); + const victimName = toBeKicked.nickname ?? toBeKicked.user.globalName; + return await interaction.reply({ content: `💥 Bang! **${victimName}** was shot.` }); }, };