Haha-Yes/commands/fun/music.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-09-07 22:48:43 +02:00
const { Command } = require('discord.js-commando');
const ytdl = require('ytdl-core');
module.exports = class MusicCommand extends Command {
constructor(client) {
super(client, {
name: 'music',
group: 'fun',
memberName: 'music',
description: 'Play youtube link in vocal',
args: [
{
key: 'ytblink',
2018-09-08 16:45:27 +02:00
prompt: 'Wich Youtube link would you like to play?\nTo stop the bot just do "haha music stop"',
2018-09-07 22:48:43 +02:00
type: 'string',
}
]
});
}
run(message, { ytblink }) {
const { voiceChannel } = message.member;
if (!voiceChannel) {
return message.reply('please join a voice channel first!');
}
2018-09-08 00:39:41 +02:00
if (ytblink == 'stop') {
voiceChannel.leave()
} else
2018-09-07 22:48:43 +02:00
voiceChannel.join().then(connection => {
const stream = ytdl(ytblink, { filter: 'audioonly' });
const dispatcher = connection.playStream(stream);
dispatcher.on('end', () => voiceChannel.leave());
});
}
};