2020-02-05 20:02:53 +00:00
|
|
|
const YouTube = require("simple-youtube-api");
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'play',
|
|
|
|
alias: 'p',
|
2020-02-24 18:41:40 +00:00
|
|
|
usage: '<song name>',
|
2020-02-05 20:02:53 +00:00
|
|
|
description: 'Play some music.',
|
|
|
|
onlyDev: false,
|
|
|
|
permission: 'none',
|
|
|
|
category: 'music',
|
2020-03-21 17:49:25 +00:00
|
|
|
async execute(msg, args, client, Discord, command) {
|
2020-02-05 20:02:53 +00:00
|
|
|
const youtube = new YouTube(client.config.api_key);
|
|
|
|
const searchString = args.slice(1).join(" ");
|
|
|
|
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
|
2020-03-14 16:38:02 +00:00
|
|
|
const queue = client.queue.get(msg.guild.id);
|
2020-02-05 20:02:53 +00:00
|
|
|
const voiceChannel = msg.member.voice.channel;
|
2020-03-14 16:38:02 +00:00
|
|
|
if (!queue) {
|
2020-03-12 11:56:31 +00:00
|
|
|
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
|
2020-02-05 20:02:53 +00:00
|
|
|
} else {
|
2020-03-14 16:38:02 +00:00
|
|
|
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
|
2020-02-05 20:02:53 +00:00
|
|
|
}
|
2020-03-12 11:56:31 +00:00
|
|
|
if (!args[1]) return msg.channel.send(client.messages.noQuery);
|
2020-03-14 16:38:02 +00:00
|
|
|
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
|
|
|
|
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
|
|
|
|
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
|
2020-02-05 20:02:53 +00:00
|
|
|
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
|
2020-03-12 11:56:31 +00:00
|
|
|
const lmsg = await msg.channel.send(client.messages.loadingSongs);
|
2020-02-05 20:02:53 +00:00
|
|
|
const playlist = await youtube.getPlaylist(url);
|
|
|
|
const videos = await playlist.getVideos();
|
|
|
|
for (const video of Object.values(videos)) {
|
2020-03-12 11:56:31 +00:00
|
|
|
const video2 = await youtube.getVideoByID(video.id);
|
2020-02-05 20:02:53 +00:00
|
|
|
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true);
|
|
|
|
}
|
2020-03-12 11:56:31 +00:00
|
|
|
client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
|
|
|
|
return lmsg.edit(client.messages.playlistAdded);
|
2020-02-05 20:02:53 +00:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
var video = await youtube.getVideo(url);
|
|
|
|
} catch (error) {
|
|
|
|
try {
|
|
|
|
const videos = await youtube.searchVideos(searchString, 1);
|
|
|
|
var video = await youtube.getVideoByID(videos[0].id);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
2020-03-19 14:45:05 +00:00
|
|
|
if (err.code === 403) {
|
|
|
|
return msg.channel.send(client.messages.quotaReached);
|
|
|
|
}
|
2020-03-12 11:56:31 +00:00
|
|
|
return msg.channel.send(client.messages.noResults);
|
2020-02-05 20:02:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return client.funcs.handleVideo(video, msg, voiceChannel, client, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|