Haha-Yes/commands/utility/play

61 lines
1.8 KiB
Text
Raw Permalink Normal View History

2019-04-06 20:45:12 +02:00
const { Command } = require('discord-akairo');
const ytdl = require('ytdl-core');
class playCommand extends Command {
constructor() {
super('play', {
aliases: ['play'],
category: 'utility',
clientPermissions: ['SEND_MESSAGES', 'SPEAK', 'CONNECT'],
2019-04-06 20:45:12 +02:00
args: [
{
id: 'ytblink',
type: 'string',
2019-06-23 03:41:59 +02:00
prompt: {
2019-11-15 21:39:53 +01:00
start: 'Send the link of which video you want to play',
2019-06-23 03:41:59 +02:00
},
2019-04-06 20:45:12 +02:00
match: 'rest',
}
],
description: {
2019-11-09 13:45:34 +01:00
content: 'play music from the link you send ( WIP & very basic at the moment )',
2019-04-06 20:45:12 +02:00
usage: '[youtube link]',
examples: ['https://www.youtube.com/watch?v=mzHWLLn5Z4A']
}
});
}
async exec(message, args) {
if(!message.channel.permissionsFor(this.client.user).has('CONNECT')) return message.channel.send('Im missing the required permissions for this command!, `VOICE_JOIN_CHANNEL`');
2019-04-06 20:45:12 +02:00
const voiceChannel = message.member.voice.channel;
// If not in voice channel ask user to join
if (!voiceChannel) {
return message.reply('please join a voice channel first!');
} else
// If user say "stop" make the bot leave voice channel
if (args.ytblink == 'stop') {
voiceChannel.leave();
return message.channel.send('I left the channel');
2019-04-06 20:45:12 +02:00
} else
voiceChannel.join().then(connection => {
const stream = ytdl(args.ytblink, { filter: 'audioonly' });
const dispatcher = connection.play(stream);
message.channel.send('Playing it now!');
2019-04-06 20:45:12 +02:00
// End at then end of the audio stream
dispatcher.on('end', () => {
voiceChannel.leave();
return message.channel.send('Music ended, i left the channel');
});
2019-11-09 11:26:10 +01:00
})
.catch(err => {
console.error(err);
voiceChannel.leave();
return message.channel.send('An error has occured! is the link you sent valid?');
});
2019-04-06 20:45:12 +02:00
}
}
2019-11-09 11:26:10 +01:00
module.exports = playCommand;