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 ) {
2020-03-09 11:17:47 +00:00
let url = args [ 1 ] ? args [ 1 ] . replace ( /<(.+)>/g , "$1" ) : "" ;
2020-03-02 19:38:42 +00:00
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 {
2020-03-08 15:42:27 +00:00
if ( voiceChannel !== radio . voiceChannel ) return msg . channel . send ( '<:redx:674263474704220182> I\'m sorry but you need to be in the same voice channel as RadioX to play music!' ) ;
2020-03-02 19:38:42 +00:00
}
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-09 11:17:47 +00:00
let station ;
const number = parseInt ( args [ 1 ] - 1 ) ;
if ( url . startsWith ( 'http' ) ) {
return ;
} else if ( ! isNaN ( number ) ) {
if ( number > client . stations . length - 1 ) {
2020-03-09 11:28:37 +00:00
return msg . channel . send ( '<:redx:674263474704220182> no such station!' ) ;
2020-03-09 11:17:47 +00:00
} else {
url = client . stations [ number ] . stream [ client . stations [ number ] . stream . default ] ;
station = client . stations [ number ] ;
}
} else {
const sstation = await client . funcs . searchStation ( args . slice ( 1 ) . join ( ' ' ) , client ) ;
if ( sstation === false ) return msg . channel . send ( 'No stations found!' ) ;
url = sstation . stream [ sstation . stream . default ] ;
station = sstation
}
2020-03-07 20:07:54 +00:00
if ( radio ) {
2020-03-08 15:03:39 +00:00
radio . connection . dispatcher . destroy ( ) ;
2020-03-09 11:17:47 +00:00
radio . station = station ;
client . funcs . play ( msg . guild , client , url ) ;
2020-03-08 15:31:53 +00:00
return ;
2020-03-07 20:07:54 +00:00
}
2020-03-09 11:17:47 +00:00
const construct = {
2020-03-07 20:07:54 +00:00
textChannel : msg . channel ,
voiceChannel : voiceChannel ,
connection : null ,
playing : false ,
2020-03-09 11:17:47 +00:00
station : station ,
2020-03-07 20:07:54 +00:00
volume : client . config . volume ,
2020-03-09 11:17:47 +00:00
time : null
2020-03-07 20:07:54 +00:00
} ;
client . radio . set ( msg . guild . id , construct ) ;
2020-03-09 11:17:47 +00:00
2020-03-07 20:07:54 +00:00
try {
const connection = await voiceChannel . join ( ) ;
construct . connection = connection ;
2020-03-09 11:17:47 +00:00
client . funcs . play ( msg . guild , client , url ) ;
2020-03-07 20:07:54 +00:00
} 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
}
} ;