2020-03-02 19:38:42 +00:00
module . exports = {
name : 'play' ,
alias : 'p' ,
usage : '<song name>' ,
description : 'Play some music.' ,
permission : 'none' ,
category : 'music' ,
async execute ( msg , args , client , Discord , prefix ) {
const url = args [ 1 ] ? args [ 1 ] . replace ( /<(.+)>/g , "$1" ) : "" ;
const radio = client . radio . get ( msg . guild . id ) ;
const voiceChannel = msg . member . voice . channel ;
if ( ! radio ) {
if ( ! msg . member . voice . channel ) return msg . channel . send ( '<:redx:674263474704220182> I\'m sorry but you need to be in a voice channel to play music!' ) ;
} else {
if ( voiceChannel !== radio . voiceChannel ) return msg . channel . send ( '<:redx:674263474704220182> I\'m sorry but you need to be in the same voice channel as Musix to play music!' ) ;
}
if ( ! args [ 1 ] ) return msg . channel . send ( '<:redx:674263474704220182> You need to use a link or search for a song!' ) ;
const permissions = voiceChannel . permissionsFor ( msg . client . user ) ;
if ( ! permissions . has ( 'CONNECT' ) ) {
return msg . channel . send ( '<:redx:674263474704220182> I cannot connect to your voice channel, make sure I have the proper permissions!' ) ;
}
if ( ! permissions . has ( 'SPEAK' ) ) {
return msg . channel . send ( '<:redx:674263474704220182> I cannot speak in your voice channel, make sure I have the proper permissions!' ) ;
}
2020-03-07 20:07:54 +00:00
if ( radio ) {
2020-03-08 15:03:39 +00:00
radio . connection . dispatcher . destroy ( ) ;
client . funcs . play ( msg . guild , client , url ) ;
2020-03-08 15:31:53 +00:00
return ;
2020-03-07 20:07:54 +00:00
}
const construct = {
textChannel : msg . channel ,
voiceChannel : voiceChannel ,
connection : null ,
playing : false ,
url : url ,
name : null ,
volume : client . config . volume ,
} ;
client . radio . set ( msg . guild . id , construct ) ;
try {
const connection = await voiceChannel . join ( ) ;
construct . connection = connection ;
client . funcs . play ( msg . guild , client , url ) ;
} catch ( error ) {
client . radio . delete ( msg . guild . id ) ;
client . debug _channel . send ( "Error with connecting to voice channel: " + error ) ;
return msg . channel . send ( ` <:redx:674263474704220182> An error occured: ${ error } ` ) ;
}
2020-03-02 19:38:42 +00:00
}
} ;