forked from BotStudios/Music-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.js
33 lines (26 loc) · 815 Bytes
/
commands.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const downloadYT = require('ytdl-core');
const searchYT = require('yt-search');
async function play(msg, ...args) {
const vc = msg.member.voice.channel;
const connection = await vc.join();
const video = await findVideo(args.join(' '));
if (video) {
const stream = downloadYT(video.url, { filter: 'audioonly' });
connection.play(stream, { seek: 0, volume: 1 });
await msg.reply(`Now playing \`${video.title}\`.`);
} else
await msg.reply(`No results found.`);
}
async function findVideo(query) {
const result = await searchYT(query);
return (result.videos.length > 1)
? result.videos[0]
: null;
}
async function stop(msg) {
const vc = msg.member.voice.channel;
await vc.leave();
await msg.reply('Stopped.');
}
module.exports.play = play;
module.exports.stop = stop;