2024-02-09 09:53:30 +00:00
const { PermissionFlagsBits } = require ( "discord.js" ) ;
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 ,
2024-02-09 09:53:30 +00:00
execute ( message , args , client , prefix ) {
const voiceChannel = message . member . voice . channel ;
2019-08-02 08:32:00 +00:00
const serverQueue = client . queue . get ( message . guild . id ) ;
const permissions = message . channel . permissionsFor ( message . author ) ;
2019-11-23 07:17:43 +00:00
if ( ! serverQueue ) return message . channel . send ( ':x: There is nothing playing that I could skip for you.' ) ;
2019-11-22 18:51:41 +00:00
if ( ! serverQueue . playing ) return message . channel . send ( ':x: There is nothing playing that I could skip for you.' ) ;
2024-02-09 09:53:30 +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!' ) ;
if ( client . global . db . guilds [ message . guild . id ] . permissions === true ) {
if ( ! message . member . roles . cache . has ( client . global . db . guilds [ message . guild . id ] . djrole ) && ! permissions . has ( PermissionFlagsBits . ManageMessages ) ) {
2019-11-19 13:59:14 +00:00
return vote ( serverQueue , message , client ) ;
2024-02-09 09:53:30 +00:00
} else {
return skipSong ( serverQueue , message ) ;
2019-10-10 13:43:04 +00:00
}
2019-11-19 13:59:14 +00:00
} else {
2024-02-09 09:53:30 +00:00
return vote ( serverQueue , message , client ) ;
2019-08-14 12:26:33 +00:00
}
2019-11-19 13:59:14 +00:00
}
} ;
function skipSong ( serverQueue , message ) {
message . channel . send ( ':fast_forward: Skipped the song!' ) ;
2024-02-09 09:53:30 +00:00
serverQueue . audioPlayer . stop ( ) ;
2019-11-19 13:59:14 +00:00
} ;
function vote ( serverQueue , message ) {
2024-02-09 09:53:30 +00:00
serverQueue . votesNeeded = Math . floor ( serverQueue . voiceChannel . members . size / 2 ) ;
2019-11-19 13:59:14 +00:00
serverQueue . votesNeeded . toFixed ( ) ;
2024-02-09 09:53:30 +00:00
if ( serverQueue . voiceChannel . members . size > 2 ) {
2019-11-19 13:59:14 +00:00
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
}
} ;