aboutsummaryrefslogtreecommitdiff
path: root/src/commands/play.js
diff options
context:
space:
mode:
authorIndrajith K L2021-06-19 18:30:58 +0530
committerIndrajith K L2021-06-19 18:30:58 +0530
commit0ef3c83f4049227c08731e3f31e53c38e1da5957 (patch)
tree349b423111db5a8730864b8c555bb15564622377 /src/commands/play.js
parentcaebd6b3e5315d3002107464b33ae7b6bf006800 (diff)
downloadradio-bot-0ef3c83f4049227c08731e3f31e53c38e1da5957.tar.gz
radio-bot-0ef3c83f4049227c08731e3f31e53c38e1da5957.tar.bz2
radio-bot-0ef3c83f4049227c08731e3f31e53c38e1da5957.zip
* Radio Bot Implementation
Diffstat (limited to 'src/commands/play.js')
-rw-r--r--src/commands/play.js52
1 files changed, 0 insertions, 52 deletions
diff --git a/src/commands/play.js b/src/commands/play.js
deleted file mode 100644
index 9c2d7a3..0000000
--- a/src/commands/play.js
+++ /dev/null
@@ -1,52 +0,0 @@
-const ytdl = require('ytdl-core');
-const ytSearch = require('yt-search');
-async function playMusik(client, message, args) {
- const voiceChannel = message.member.voice.channel;
- if (!voiceChannel) {
- return message.channel.send("Join a voice channel to Play Music");
- }
- const permission = voiceChannel.permissionsFor(message.client.user);
- if (!permission.has('CONNECT') || !permission.has('SPEAK')) {
- return message.channel.send("You don't have the permission to play music. 😥");
- }
-
- if (!args.length) {
- return message.channel.send("Please pass something to play as second argument");
- }
-
- const connection = await voiceChannel.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(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 ${videoUrl ? args[0] : video.title}...`);
- } else {
- message.channel.send("No music found to play for you mate. Try again! 👍");
- }
-}
-
-async function searchVideo(query) {
- const searchResult = await ytSearch(query);
- return (searchResult.videos.length > 1) ? searchResult.videos[0] : null;
-}
-
-
-module.exports = {
- execute(client,message, args) {
- playMusik(client,message,args);
- }
-} \ No newline at end of file