From ac4839ded1a87b85aab901fd29c0f8875189a98f Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 20 Jul 2020 14:43:33 -0400 Subject: Removed fetchAudio and it actually shuffles --- bot.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'bot.js') diff --git a/bot.js b/bot.js index 643aeec..e2b0170 100644 --- a/bot.js +++ b/bot.js @@ -14,22 +14,24 @@ let botOwner = "242775871059001344"; var voiceChannel = "734184921433899108"; var prefix = "!"; -function fetchAudio() { - fs.readdir('./music', (err, files) => { - if (err) console.error(err); - files.forEach(function (file) { - console.log(`Fetching ${file}`); - }); - }); -} - function playAudio() { + let audio; const channel = client.channels.cache.get(voiceChannel); if (!channel) return console.error("The channel does not exist!"); + + fs.readdir('./music', (err, files) => { + if (err) console.error(err); + audio = files[Math.floor(Math.random() * files.length)]; + return audio; + }); + channel.join().then(connection => { console.log("Connected to the voice channel."); - fetchAudio(); - connection.play('./music/4616-werq-by-kevin-macleod.mp3'); + const dispatcher = connection.play("./music/" + audio); + + console.log("Project Jul-2020 Bot:\nNow playing " + audio); + let serviceChannel = client.channels.cache.get('606602551634296968'); + serviceChannel.send("**Project Jul-2020 Bot:**\nNow playing " + audio); }).catch(e => { console.error(e); }); @@ -69,7 +71,7 @@ client.on('message', async msg => { playAudio(); } if (command == 'skip') { - //TODO + //This feature might not make it in } if (command == 'leave') { const channel = client.channels.cache.get(voiceChannel); -- cgit v1.2.3