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
MatteZ02 a64f9d2325 Update 3.0.3
All messages reworked.
2020-03-12 13:56:31 +02:00

51 lines
1.9 KiB
JavaScript

module.exports = {
name: 'skip',
alias: 's',
usage: '',
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(client.messages.noServerQueue);
if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== serverQueue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
if (client.global.db.guilds[msg.guild.id].permissions) {
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole) || !permissions.has(command.permission)) {
return vote(serverQueue, msg, client);
} else {
return skipSong(serverQueue, msg, client);
}
} else {
return skipSong(serverQueue, msg, client);
}
} else {
return skipSong(serverQueue, msg, client);
}
}
};
function skipSong(serverQueue, msg, client) {
msg.channel.send(client.messages.skipped);
serverQueue.endReason = "skip";
serverQueue.connection.dispatcher.end();
};
function vote(serverQueue, msg, client) {
serverQueue.votesNeeded = Math.floor(serverQueue.voiceChannel.members.size / 2);
serverQueue.votesNeeded.toFixed();
if (serverQueue.voiceChannel.members.size > 2) {
if (serverQueue.voters.includes(msg.member.id)) return msg.channel.send(client.messages.alreadyVoted);
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(`${client.messages.notEnoughVotes} ${serverQueue.votes} / ${serverQueue.votesNeeded}!`);
} else {
return skipSong(serverQueue, msg);
}
};