From 83906b211d856317c657302721b044481d5829b8 Mon Sep 17 00:00:00 2001 From: Ecolipsy Date: Thu, 2 Dec 2021 17:07:01 +0100 Subject: [PATCH] Add directory check --- index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.js b/index.js index 195bebe..7744da5 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,23 @@ const dc = require("discord.js"); const client = new dc.Client({intents: ["GUILDS", "GUILD_MESSAGES"]}); const fs = require("fs"); +function isDir(path){ + try{ + fs.readdirSync(path); + return true; + } catch(e){ + return false; + } +} + function parseCommands(){ var cmdFiles = []; var indexes = {} var rootdir = fs.readdirSync("Juustobotti/commands"); rootdir.forEach(categorydir => { + if(!isDir("Juustobotti/commands/" + categorydir)) return; categorydir.forEach(file => { + if(isDir("Juustobotti/commands/" + categorydir + "/" + file)) return; indexes.file = categorydir; cmdFiles.push(file); });