mirror of
https://github.com/warengroup/eximiabots-radiox.git
synced 2024-11-09 23:00:18 +00:00
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
module.exports = {
|
|
name: 'play',
|
|
alias: 'p',
|
|
usage: '<song name>',
|
|
description: 'Play some music.',
|
|
onlyDev: false,
|
|
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!');
|
|
}
|
|
|
|
if (radio) {
|
|
radio.connection.dispatcher.end();
|
|
}
|
|
|
|
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}`);
|
|
}
|
|
}
|
|
};
|