forked from Supositware/Haha-Yes
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
Plaintext
61 lines
1.8 KiB
Plaintext
6 years ago
|
const { Command } = require('discord-akairo');
|
||
|
const ytdl = require('ytdl-core');
|
||
|
|
||
|
class playCommand extends Command {
|
||
|
constructor() {
|
||
|
super('play', {
|
||
|
aliases: ['play'],
|
||
|
category: 'utility',
|
||
5 years ago
|
clientPermissions: ['SEND_MESSAGES', 'SPEAK', 'CONNECT'],
|
||
6 years ago
|
args: [
|
||
|
{
|
||
|
id: 'ytblink',
|
||
|
type: 'string',
|
||
5 years ago
|
prompt: {
|
||
5 years ago
|
start: 'Send the link of which video you want to play',
|
||
5 years ago
|
},
|
||
6 years ago
|
match: 'rest',
|
||
|
}
|
||
|
],
|
||
|
description: {
|
||
5 years ago
|
content: 'play music from the link you send ( WIP & very basic at the moment )',
|
||
6 years ago
|
usage: '[youtube link]',
|
||
|
examples: ['https://www.youtube.com/watch?v=mzHWLLn5Z4A']
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
async exec(message, args) {
|
||
5 years ago
|
if(!message.channel.permissionsFor(this.client.user).has('CONNECT')) return message.channel.send('Im missing the required permissions for this command!, `VOICE_JOIN_CHANNEL`');
|
||
6 years ago
|
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();
|
||
5 years ago
|
return message.channel.send('I left the channel');
|
||
6 years ago
|
} else
|
||
|
voiceChannel.join().then(connection => {
|
||
|
const stream = ytdl(args.ytblink, { filter: 'audioonly' });
|
||
|
const dispatcher = connection.play(stream);
|
||
5 years ago
|
message.channel.send('Playing it now!');
|
||
6 years ago
|
// End at then end of the audio stream
|
||
5 years ago
|
dispatcher.on('end', () => {
|
||
|
voiceChannel.leave();
|
||
|
return message.channel.send('Music ended, i left the channel');
|
||
|
});
|
||
5 years ago
|
})
|
||
|
.catch(err => {
|
||
|
console.error(err);
|
||
|
voiceChannel.leave();
|
||
|
return message.channel.send('An error has occured! is the link you sent valid?');
|
||
|
});
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
module.exports = playCommand;
|