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
+24
View File
@@ -0,0 +1,24 @@
const { Command } = require('discord.js-commando');
module.exports = class JoinCommand extends Command {
constructor(client) {
super(client, {
name: 'join',
memberName: 'join',
group: 'music',
description: 'joins a voice channel',
aliases: ['summon'],
guildOnly: true
});
}
async run(message) {
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.reply('you need to join a channel!');
const connection = await voiceChannel.join();
return message.say('joined!');
}
}
+23
View File
@@ -0,0 +1,23 @@
const { Command } = require('discord.js-commando');
module.exports = class Leave extends Command {
constructor(client) {
super(client, {
name: 'leave',
memberName: 'leave',
group: 'music',
description: 'leaves a voice channel',
guildOnly: true
});
}
async run(message) {
if (!message.member.voice.channel) return message.reply('you need to join a channel!');
const voiceChannel = message.member.voice.channel;
voiceChannel.leave();
return message.say('left!');
}
}
+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!');
}
}
}
+23
View File
@@ -0,0 +1,23 @@
const { Command } = require('discord.js-commando');
module.exports = class Play extends Command {
constructor(client) {
super(client, {
name: 'stop',
memberName: 'stop',
group: 'music',
description: 'stops the player and leaves the channel',
guildOnly: true
});
}
async run(message) {
if (!message.member.voice.channel) return message.reply('you need to join a channel!');
const voiceChannel = message.member.voice.channel;
voiceChannel.leave();
return message.say('stopped!');
}
}