From e90fccb87877578320865a49c54eb7b9bd6b4fdf Mon Sep 17 00:00:00 2001 From: Catalin Ta Date: Sun, 24 Dec 2023 17:07:53 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20added:=20vote=20to=20skip=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/player/skip.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/commands/player/skip.js b/commands/player/skip.js index 885704d..dc308a1 100644 --- a/commands/player/skip.js +++ b/commands/player/skip.js @@ -3,6 +3,8 @@ const { SlashCommandBuilder } = require('discord.js'); const { Player } = require('discord-player'); +const skipVotes = new Map(); + module.exports = class Skip extends Command { constructor(client) { super(client, { @@ -15,6 +17,7 @@ module.exports = class Skip extends Command { permissions: ['Use Application Commands', 'Send Messages', 'Embed Links'], }); } + async run(client, interaction) { const player = Player.singleton(); const queue = player.nodes.get(interaction.guild.id); @@ -23,7 +26,20 @@ module.exports = class Skip extends Command { return await interaction.reply('<:red_emoji:1126936340022435963> There isn\'t currently any music playing.'); } - queue.node.skip(); - return await interaction.reply(`<:green_emoji:1126936345043030026> The track **${queue.currentTrack.title}** was skipped.`); + const usersInChannel = interaction.member.voice.channel.members.size; + if (!skipVotes[interaction.guild.id]) { + skipVotes[interaction.guild.id] = new Set(); + } + const skipVotesTotal = skipVotes[interaction.guild.id]; + skipVotesTotal.add(interaction.user.id); + + if (skipVotesTotal.size >= Math.ceil(usersInChannel * 0.35)) { + queue.node.skip(); + skipVotes[interaction.guild.id] = new Set(); + return await interaction.reply(`<:green_emoji:1126936345043030026> The track **${queue.currentTrack.title}** was skipped.`); + } + else { + return await interaction.reply(`You voted to skip. Required ${Math.ceil(usersInChannel * 0.35) - skipVotes.size - 1} more vote(s) needed to skip the track.`); + } } -}; \ No newline at end of file +};