From b42e97519c5157c70cbb8ef0a16e66b204f57284 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 21 Jul 2020 17:13:52 -0400 Subject: Made some changes with the voice channel variable --- bot.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'bot.js') diff --git a/bot.js b/bot.js index e36c90f..736bcb5 100644 --- a/bot.js +++ b/bot.js @@ -24,14 +24,15 @@ const client = new Discord.Client(); const config = require('./config.json'); let dispatcher; let audio; +let voiceChannel; client.login(config.token); function playAudio() { - const channel = client.channels.cache.get(config.voiceChannel); - if (!channel) return console.error('The voice channel does not exist!\n(Have you looked at your configuration?)'); + voiceChannel = client.channels.cache.get(config.voiceChannel); + if (!voiceChannel) return console.error('The voice channel does not exist!\n(Have you looked at your configuration?)'); - channel.join().then(connection => { + voiceChannel.join().then(connection => { let files = fs.readdirSync('./music'); while (true) { @@ -130,12 +131,12 @@ client.on('message', async msg => { } if (command == 'leave') { - const channel = client.channels.cache.get(config.voiceChannel); - if (!channel) return console.error('The voice channel does not exist!\n(Have you looked at your configuration?)'); + voiceChannel = client.channels.cache.get(config.voiceChannel); + if (!voiceChannel) return console.error('The voice channel does not exist!\n(Have you looked at your configuration?)'); msg.reply('Leaving voice channel.'); console.log('Leaving voice channel.'); dispatcher.destroy(); - channel.leave(); + voiceChannel.leave(); } if (command == 'stop') { -- cgit v1.2.3