aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndrajith K L2021-06-18 17:41:22 +0530
committerIndrajith K L2021-06-18 17:41:22 +0530
commitcaebd6b3e5315d3002107464b33ae7b6bf006800 (patch)
tree3b10c63664200cb63500742318f40f6f4f498d38
parent4e86dbd1755db4ff8a1779fda8c3a167d1b24c8e (diff)
downloadradio-bot-caebd6b3e5315d3002107464b33ae7b6bf006800.tar.gz
radio-bot-caebd6b3e5315d3002107464b33ae7b6bf006800.tar.bz2
radio-bot-caebd6b3e5315d3002107464b33ae7b6bf006800.zip
Adds Support to youtube url
-rw-r--r--src/commands/play.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/commands/play.js b/src/commands/play.js
index 24e4fcd..9c2d7a3 100644
--- a/src/commands/play.js
+++ b/src/commands/play.js
@@ -15,17 +15,25 @@ async function playMusik(client, message, args) {
}
const connection = await voiceChannel.join();
- const video = await searchVideo(args.join(' '));
+ let videoUrl = false;
+ let video;
+ const youtubeRegex = /(http:|https:)?\/\/(www\.)?(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/;
+ if (youtubeRegex.test(args[0])) {
+ video = args[0];
+ videoUrl = true;
+ } else {
+ video = await searchVideo(args.join(' '));
+ }
if (video) {
- const youtubeStream = ytdl(video.url, { filter: 'audioonly' });
+ const youtubeStream = ytdl(videoUrl ? video : video.url, { filter: 'audioonly' });
client.user.setPresence({ activity: { name: `${video.title}`, type: 'LISTENING' } });
connection.play(youtubeStream, { seek: 0, volume: 1 })
.on('finish', () => {
voiceChannel.leave();
client.user.setPresence({ activity: { name: ` ` } });
});
- await message.reply(`Now Playing ${video.title}...`);
+ await message.reply(`Now Playing ${videoUrl ? args[0] : video.title}...`);
} else {
message.channel.send("No music found to play for you mate. Try again! 👍");
}