Skip to content

Commit

Permalink
✨ added: vote to skip feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Catalin Ta committed Dec 24, 2023
1 parent c042de7 commit e90fccb
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions commands/player/skip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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);
Expand All @@ -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.`);
}
}
};
};

0 comments on commit e90fccb

Please sign in to comment.