mirror of
https://github.com/hazemKrimi/discord-bot.git
synced 2026-05-01 18:30:25 +00:00
added join and leave commands
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'join',
|
||||||
|
description: 'joins a voice channel',
|
||||||
|
execute: async (message, voiceChannel, args) => {
|
||||||
|
connection = await voiceChannel.join();
|
||||||
|
connection.play('https://www.youtube.com/watch?v=Hl1s4BT9Fc4');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'leave',
|
||||||
|
description: 'leaves a voice channel',
|
||||||
|
execute: async = (message, voiceChannel, args) => {
|
||||||
|
voiceChannel.leave();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,8 +1,37 @@
|
|||||||
const Discord = require('discord.js');
|
|
||||||
const client = new Discord.Client();
|
|
||||||
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const Discord = require('discord.js');
|
||||||
|
|
||||||
|
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();
|
||||||
|
const voiceChannel = message.member.voice.channel;
|
||||||
|
|
||||||
|
if (!client.commands.has(commandName)) return message.reply('this command does not exist!');
|
||||||
|
|
||||||
|
const command = client.commands.get(commandName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
command.execute(message, voiceChannel, args);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
message.reply('there was an error trying to execute that command!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
console.log('ready');
|
console.log('ready');
|
||||||
});
|
});
|
||||||
|
|||||||
Generated
+1735
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "bantoufi-discord-bot",
|
"name": "bantoufi-discord-bot",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "a music discord bot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
@@ -18,7 +18,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/hazemKrimi/bantoufi-discord-bot#readme",
|
"homepage": "https://github.com/hazemKrimi/bantoufi-discord-bot#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@discordjs/opus": "^0.2.1",
|
||||||
"discord.js": "^12.2.0",
|
"discord.js": "^12.2.0",
|
||||||
"dotenv": "^8.2.0"
|
"dotenv": "^8.2.0",
|
||||||
|
"ffmpeg-static": "^4.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user