Haha-Yes/commands/fun/music.js

40 lines
1.2 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',
2018-09-09 21:02:12 +02:00
description: 'Play youtube link in vocal',
2018-09-07 22:48:43 +02:00
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',
}
]
});
}
2018-09-09 21:32:08 +02:00
async run(message, { ytblink }) {
2018-09-07 22:48:43 +02:00
const { voiceChannel } = message.member;
2018-09-08 23:09:33 +02:00
2018-09-08 22:30:50 +02:00
if (!voiceChannel) {
return message.reply('please join a voice channel first!');
2018-09-08 23:09:33 +02:00
} else
2018-09-08 22:30:50 +02:00
if (ytblink == 'stop') {
voiceChannel.leave()
} else
voiceChannel.join().then(connection => {
const stream = ytdl(ytblink, { filter: 'audioonly' });
const dispatcher = connection.playStream(stream);
dispatcher.on('end', () => voiceChannel.leave());
});
2018-09-08 23:09:33 +02:00
2018-09-07 22:48:43 +02:00
}
2018-09-08 23:09:33 +02:00
}