1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-14 16:00:17 +00:00
musix-oss/commands/skip.js

50 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-08-02 08:32:00 +00:00
module.exports = {
name: 'skip',
description: 'Skip command.',
2019-11-02 06:56:39 +00:00
alias: 's',
2019-08-02 08:32:00 +00:00
cooldown: 5,
onlyDev: false,
2019-10-10 13:43:04 +00:00
execute(message, args, client, Discord, prefix) {
2019-08-02 08:32:00 +00:00
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.');
2019-11-23 13:03:08 +00:00
if (message.author.id !== client.config.devId) {
2019-10-18 18:44:15 +00:00
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!');
2019-10-11 08:48:50 +00:00
if (client.global.db.guilds[message.guild.id].permissions === true) {
2019-11-19 13:59:14 +00:00
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);
2019-10-10 13:43:04 +00:00
}
2019-11-19 13:59:14 +00:00
} else {
return skipSong(serverQueue, message);
}
2019-11-19 13:59:14 +00:00
}
};
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);
2019-08-02 08:32:00 +00:00
}
};