added commando

This commit is contained in:
Hazem Krimi
2020-05-01 02:08:33 +01:00
parent 3acb006f43
commit 1e2c6e2a8b
9 changed files with 213 additions and 57 deletions
+43
View File
@@ -0,0 +1,43 @@
const { Command } = require('discord.js-commando');
const Youtube = require('simple-youtube-api');
const ytdl = require('ytdl-core-discord');
const youtube = new Youtube(process.env.YOUTUBE_API_KEY);
module.exports = class Play extends Command {
constructor(client) {
super(client, {
name: 'play',
memberName: 'play',
group: 'music',
description: 'plays audio from youtube or facebook',
guildOnly: true,
clientPermissions: ['SPEAK', 'CONNECT'],
args: [
{
key: 'query',
prompt: 'what do you want to listen to?',
type: 'string',
validate: query => query.length > 0
}
]
});
}
async run(message, { query }) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.reply('you need to join a channel!');
const connection = await voiceChannel.join();
if (query.match(/^(http(s)?:\/\/)?((w){3}.)?youtu(be|.be)?(\.com)?\/.+/)) {
const dispatcher = connection.play(await ytdl(query), { type: 'opus' });
dispatcher.on('start', () => {
return message.reply('youtube video is playing!');
});
} else {
return message.reply('currently, i only support youtube video links!');
}
}
}