mirror of
https://github.com/hazemKrimi/discord-bot.git
synced 2026-05-01 18:30:25 +00:00
added commando
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
module.exports = {
|
||||
name: 'join',
|
||||
description: 'joins a voice channel',
|
||||
execute: async(message, args) => {
|
||||
const voiceChannel = message.member.voice.channel;
|
||||
|
||||
if (!voiceChannel) return message.reply('you need to join a channel!');
|
||||
|
||||
connection = await voiceChannel.join();
|
||||
|
||||
return message.channel.send('joined!');
|
||||
}
|
||||
};
|
||||
@@ -1,13 +0,0 @@
|
||||
module.exports = {
|
||||
name: 'leave',
|
||||
description: 'leaves a voice channel',
|
||||
execute: async(message, args) => {
|
||||
if (!message.member.voice.channel) return message.reply('you need to join a channel!');
|
||||
|
||||
const voiceChannel = message.member.voice.channel;
|
||||
|
||||
voiceChannel.leave();
|
||||
|
||||
return message.channel.send('left!');
|
||||
}
|
||||
};
|
||||
@@ -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!');
|
||||
}
|
||||
}
|
||||
@@ -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!');
|
||||
}
|
||||
}
|
||||
@@ -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!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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!');
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,25 @@
|
||||
require('dotenv').config();
|
||||
|
||||
const fs = require('fs');
|
||||
const Discord = require('discord.js');
|
||||
const { CommandoClient } = require('discord.js-commando');
|
||||
const path = require('path');
|
||||
|
||||
const client = new Discord.Client();
|
||||
client.commands = new Discord.Collection();
|
||||
|
||||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`./commands/${file}`);
|
||||
client.commands.set(command.name, command);
|
||||
}
|
||||
|
||||
client.on('message', async message => {
|
||||
if (!message.content.startsWith(process.env.PREFIX) || message.author.bot) return;
|
||||
|
||||
const args = message.content.slice(process.env.PREFIX.length).split(/ +/);
|
||||
const commandName = args.shift().toLowerCase();
|
||||
|
||||
if (!client.commands.has(commandName)) return message.reply('this command does not exist!');
|
||||
|
||||
const command = client.commands.get(commandName);
|
||||
|
||||
try {
|
||||
command.execute(message, args);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.reply('there was an error trying to execute that command!');
|
||||
}
|
||||
const client = new CommandoClient({
|
||||
commandPrefix: 'b.'
|
||||
});
|
||||
|
||||
client.registry
|
||||
.registerDefaultTypes()
|
||||
.registerGroups([
|
||||
['music', 'Music Commands']
|
||||
])
|
||||
.registerDefaultGroups()
|
||||
.registerDefaultCommands()
|
||||
.registerCommandsIn(path.join(__dirname, 'commands'));
|
||||
|
||||
client.once('ready', () => {
|
||||
console.log('ready');
|
||||
client.user.setActivity('amsa7 lak7el');
|
||||
});
|
||||
|
||||
client.login(process.env.BOT_TOKEN);
|
||||
|
||||
client.on('error', console.error);
|
||||
Generated
+79
@@ -327,6 +327,11 @@
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"common-tags": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.0.tgz",
|
||||
"integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw=="
|
||||
},
|
||||
"component-emitter": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
|
||||
@@ -460,6 +465,14 @@
|
||||
"ws": "^7.2.1"
|
||||
}
|
||||
},
|
||||
"discord.js-commando": {
|
||||
"version": "github:discordjs/Commando#bdbd84e2a978322f3af12c21e729eb7b7cd4a3dc",
|
||||
"from": "github:discordjs/Commando",
|
||||
"requires": {
|
||||
"common-tags": "^1.8.0",
|
||||
"require-all": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
|
||||
@@ -769,6 +782,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"html-entities": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/html-entities/-/html-entities-1.3.1.tgz",
|
||||
"integrity": "sha512-rhE/4Z3hIhzHAUKbW8jVcCyuT5oJCXXqhN/6mXXVCpzTmvJnoH2HL/bt3EZ6p55jbFJBeAe1ZNpL5BugLujxNA=="
|
||||
},
|
||||
"http-response-object": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.2.tgz",
|
||||
@@ -941,6 +959,11 @@
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA="
|
||||
},
|
||||
"iso8601-duration": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/iso8601-duration/-/iso8601-duration-1.2.0.tgz",
|
||||
"integrity": "sha512-ErTBd++b17E8nmWII1K1uZtBgD1E8RjyvwmxlCjPHNqHMD7gmcMHOw0E8Ro/6+QT4PhHRSnnMo7bxa1vFPkwhg=="
|
||||
},
|
||||
"isobject": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
|
||||
@@ -967,6 +990,15 @@
|
||||
"graceful-fs": "^4.1.11"
|
||||
}
|
||||
},
|
||||
"m3u8stream": {
|
||||
"version": "0.6.5",
|
||||
"resolved": "https://registry.npmjs.org/m3u8stream/-/m3u8stream-0.6.5.tgz",
|
||||
"integrity": "sha512-QZCzhcfUliZfsOboi68QkNcMejPKTEhxE+s1TApvHubDeR8ythm4ViWuYFqgUwZeoHe8q0nsPxOvA3lQvdSzyg==",
|
||||
"requires": {
|
||||
"miniget": "^1.6.1",
|
||||
"sax": "^1.2.4"
|
||||
}
|
||||
},
|
||||
"map-cache": {
|
||||
"version": "0.2.2",
|
||||
"resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz",
|
||||
@@ -1013,6 +1045,11 @@
|
||||
"mime-db": "1.44.0"
|
||||
}
|
||||
},
|
||||
"miniget": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/miniget/-/miniget-1.7.0.tgz",
|
||||
"integrity": "sha512-yrgaDSMRzrfYTkudB4Y6xK8pCb7oAH2bvfv6iPY2m6CedZfs9yK4b/ofh0Vzv08hCYXH/HHkoS8an6fkWtOAQA=="
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
@@ -1377,6 +1414,11 @@
|
||||
"resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz",
|
||||
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc="
|
||||
},
|
||||
"require-all": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/require-all/-/require-all-3.0.0.tgz",
|
||||
"integrity": "sha1-Rz1JcEvjEBFc4ST3c4Ox69hnExI="
|
||||
},
|
||||
"resolve-url": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz",
|
||||
@@ -1472,6 +1514,15 @@
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",
|
||||
"integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA=="
|
||||
},
|
||||
"simple-youtube-api": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/simple-youtube-api/-/simple-youtube-api-5.2.1.tgz",
|
||||
"integrity": "sha512-vmndP9Bkh35tifn2OwY+th2imSsfYtmDqczgdOW5yEARFzvSoR8VSQFsivJnctfV5QHQUL6VrOpNdbmDRLh9Bg==",
|
||||
"requires": {
|
||||
"iso8601-duration": "^1.2.0",
|
||||
"node-fetch": "^2.6.0"
|
||||
}
|
||||
},
|
||||
"slash": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz",
|
||||
@@ -1850,6 +1901,34 @@
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
||||
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="
|
||||
},
|
||||
"ytdl-core": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/ytdl-core/-/ytdl-core-2.1.1.tgz",
|
||||
"integrity": "sha512-rg1h6enMeBzShy4ZMam8k28VQfpSdxwZprCy3t38VvHn9DHzYqVk5Lvevy4QGkASScoYr1sIKGkNo0hh7NGRnA==",
|
||||
"requires": {
|
||||
"html-entities": "^1.3.1",
|
||||
"m3u8stream": "^0.6.3",
|
||||
"miniget": "^1.7.0",
|
||||
"sax": "^1.1.3"
|
||||
}
|
||||
},
|
||||
"ytdl-core-discord": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ytdl-core-discord/-/ytdl-core-discord-1.2.0.tgz",
|
||||
"integrity": "sha512-BTE0eslSZzovThOAXbT9KZjsh2spu9y0nl9ZNrGNn4rLip8xocmYpDUEN8X03tTcGUybpzyN8J7wwM2/gNLRiA==",
|
||||
"requires": {
|
||||
"@types/node": "^13.11.1",
|
||||
"prism-media": "^1.2.1",
|
||||
"ytdl-core": "^2.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": {
|
||||
"version": "13.13.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.4.tgz",
|
||||
"integrity": "sha512-x26ur3dSXgv5AwKS0lNfbjpCakGIduWU1DU91Zz58ONRWrIKGunmZBNv4P7N+e27sJkiGDsw/3fT4AtsqQBrBA=="
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -20,8 +20,11 @@
|
||||
"dependencies": {
|
||||
"@discordjs/opus": "^0.2.1",
|
||||
"discord.js": "^12.2.0",
|
||||
"discord.js-commando": "github:discordjs/Commando",
|
||||
"dotenv": "^8.2.0",
|
||||
"ffmpeg-static": "^4.2.0",
|
||||
"sodium": "^3.0.2"
|
||||
"simple-youtube-api": "^5.2.1",
|
||||
"sodium": "^3.0.2",
|
||||
"ytdl-core-discord": "^1.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user