1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-10 08:10:18 +00:00
musix-oss/commands/skip.js

50 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-02-05 20:02:53 +00:00
module.exports = {
name: 'skip',
alias: 's',
2020-02-24 18:41:40 +00:00
usage: '',
2020-02-05 20:02:53 +00:00
description: 'Skip the currently playing song.',
onlyDev: false,
permission: 'MANAGE_MESSAGES',
category: 'music',
execute(msg, args, client, Discord, prefix, command) {
const serverQueue = client.queue.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author);
if (!serverQueue || !serverQueue.playing) return msg.channel.send('<:redx:674263474704220182> There is nothing playing!');
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== serverQueue.voiceChannel) return msg.channel.send('<:redx:674263474704220182> I\'m sorry but you need to be in the same voice channel as Musix!');
if (client.global.db.guilds[msg.guild.id].permissions === true) {
2020-02-19 20:00:42 +00:00
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole) && !permissions.has(command.permission)) {
2020-02-05 20:02:53 +00:00
return vote(serverQueue, msg, client);
} else {
return skipSong(serverQueue, msg);
}
} else {
return vote(serverQueue, msg, client);
}
} else {
return skipSong(serverQueue, msg);
}
}
};
function skipSong(serverQueue, msg) {
msg.channel.send('<:skip:674685614221688832> Skipped the song!');
serverQueue.connection.dispatcher.end('skipped');
};
function vote(serverQueue, msg) {
2020-02-10 19:53:49 +00:00
serverQueue.votesNeeded = Math.floor(serverQueue.voiceChannel.members.size / 2);
2020-02-05 20:02:53 +00:00
serverQueue.votesNeeded.toFixed();
2020-02-10 19:56:43 +00:00
if (serverQueue.voiceChannel.members.size > 2) {
2020-02-05 20:02:53 +00:00
if (serverQueue.voters.includes(msg.member.id)) return msg.channel.send('<:redx:674263474704220182> You have already voted to skip!');
serverQueue.votes++;
serverQueue.voters.push(msg.member.id);
if (serverQueue.votes >= serverQueue.votesNeeded) {
serverQueue.voters = [];
serverQueue.votes = 0;
serverQueue.votesNeeded = null;
return skipSong(serverQueue, msg);
} else return msg.channel.send(`<:redx:674263474704220182> Not enough votes! ${serverQueue.votes} / ${serverQueue.votesNeeded}!`);
} else {
return skipSong(serverQueue, msg);
}
};