avoid bots being kicked by /shoot
Marco Andronaco andronacomarco@gmail.com
Sun, 21 Jan 2024 11:17:46 +0100
1 files changed,
6 insertions(+),
4 deletions(-)
jump to
M
src/commands/shoot.ts
→
src/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.` }); }, };