1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-14 03:30:18 +00:00
musix-oss/commands/skip.js
2019-11-23 15:03:08 +02:00

50 lines
2.1 KiB
JavaScript

module.exports = {
name: 'skip',
description: 'Skip command.',
alias: 's',
cooldown: 5,
onlyDev: false,
execute(message, args, client, Discord, prefix) {
const { voiceChannel } = message.member;
const serverQueue = client.queue.get(message.guild.id);
const permissions = message.channel.permissionsFor(message.author);
if (!serverQueue) return message.channel.send(':x: There is nothing playing that I could skip for you.');
if (!serverQueue.playing) return message.channel.send(':x: There is nothing playing that I could skip for you.');
if (message.author.id !== client.config.devId) {
if (voiceChannel !== serverQueue.voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in the same voice channel as Musix to skip the song!');
if (client.global.db.guilds[message.guild.id].permissions === true) {
if (!message.member.roles.has(client.global.db.guilds[message.guild.id].djrole) && !permissions.has('MANAGE_MESSAGES')) {
return vote(serverQueue, message, client);
} else {
return skipSong(serverQueue, message);
}
} else {
return vote(serverQueue, message, client);
}
} else {
return skipSong(serverQueue, message);
}
}
};
function skipSong(serverQueue, message) {
message.channel.send(':fast_forward: Skipped the song!');
serverQueue.connection.dispatcher.end('skipped');
};
function vote(serverQueue, message) {
serverQueue.votesNeeded = Math.floor(message.guild.voiceConnection.channel.members.size / 2);
serverQueue.votesNeeded.toFixed();
if (message.guild.voiceConnection.channel.members.size > 2) {
if (serverQueue.voters.includes(message.member.id)) return message.channel.send(':x: You have already voted to skip!');
serverQueue.votes++;
serverQueue.voters.push(message.member.id);
if (serverQueue.votes >= serverQueue.votesNeeded) {
serverQueue.voters = [];
serverQueue.votes = 0;
serverQueue.votesNeeded = null;
return skipSong(serverQueue, message);
} else return message.channel.send(`:x: Not enough votes! ${serverQueue.votes} / ${serverQueue.votesNeeded}!`);
} else {
return skipSong(serverQueue, message);
}
};