From 3acb006f43f7493346c0b3c6082049eb9d42b090 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Wed, 29 Apr 2020 10:46:29 +0100 Subject: [PATCH] improved basic commands --- commands/join.js | 7 ++++++- commands/leave.js | 8 +++++++- index.js | 3 +-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/commands/join.js b/commands/join.js index 92c7e89..7ac0d61 100644 --- a/commands/join.js +++ b/commands/join.js @@ -1,8 +1,13 @@ module.exports = { name: 'join', description: 'joins a voice channel', - execute: async (message, voiceChannel, args) => { + 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!'); } }; \ No newline at end of file diff --git a/commands/leave.js b/commands/leave.js index c121af0..90dd4ed 100644 --- a/commands/leave.js +++ b/commands/leave.js @@ -1,7 +1,13 @@ module.exports = { name: 'leave', description: 'leaves a voice channel', - execute: async = (message, voiceChannel, args) => { + 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!'); } }; \ No newline at end of file diff --git a/index.js b/index.js index 1eb6f3e..477c544 100644 --- a/index.js +++ b/index.js @@ -18,14 +18,13 @@ client.on('message', async message => { 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); + command.execute(message, args); } catch (error) { console.error(error); message.reply('there was an error trying to execute that command!');