title: Discord Bot | DiscordJS | Javascript
body: <p>so I've been working on a Discord bot using the Discord.JS library and I've ran into a problem. Pretty sure the problem is more related to Javascript versus Discord.JS so I'll ask here and hope for some assistance.</p>
  
  <p>I have a file called commandManager.js that holds all my basic command functions. One of them being autoloading the commands from the /commands/ folder and assigning them to an array based off of their category (which is specified in the command via exports). </p>
  
  <pre><code>global.userCommands = {};
  global.modCommands = {};
  global.adminCommands = {};
  global.ownerCommands = {};
  
  exports.init = function(bot)
  {
      fs.readdir("./commands/", (error, files) =&gt;
      {
          if (error)
          {
              logger.error(error);
          }
  
          files.forEach(file =&gt;
          {
              let commandFile = require(`../commands/${file}`);
              let commandName = file.split(".")[0];
              if (commandFile.info.category == "User")
              {
                  userCommands[commandName] = commandFile;
              }
              else if (commandFile.info.category == "Mod")
              {
                  modCommands[commandName] = commandFile;
              }
              else if (commandFile.info.category == "Admin")
              {
                  adminCommands[commandName] = commandFile;
              }
              else if (commandFile.info.category == "Owner")
              {
                  ownerCommands[commandName] = commandFile;
              }
              else
              {
                  logger.warn("Could not add the command " + commandName + " to any of the categories");
              }
          });
  
          logger.info("Loaded " + files.length + " command(s)");
      });
  }
  </code></pre>
  
  <p>Then after this I can use a command in the actual bot on message bit which I did as following:</p>
  
  <pre><code>exports.run = function(bot, msg)
  {   
      const args = msg.content.slice(config.prefix.length).trim().split(/ +/g);
      const command = args.shift().toLowerCase();
      const cleanCommand = command.slice(config.prefix.length);
  
      if (msg.author.bot)
      {
          return;
      }   
      else if (msg.content.indexOf(config.prefix) !== 0) 
      {
          return;
      }   
      else if (has.call(userCommands, cleanCommand))
      {
          msg.reply("user");
      }
      else if (has.call(modCommands, cleanCommand))
      {
  
      }
      else if (has.call(adminCommands, cleanCommand))
      {
  
      }
      else if (has.call(ownerCommands, cleanCommand))
      {
  
      }
      else
      {
          msg.reply(`that command does not even exist! You can say ${config.prefix}help for a list of commands!`);
      }
  }
  </code></pre>
  
  <p>So when I say the command for example "ping" it SHOULD reply with msg.reply("user") but instead it says it doesn't exist whatsoever. I declared has as a global like this incase you were curious.</p>
  
  <pre><code>global.has = Object.prototype.hasOwnProperty;
  </code></pre>
  
  <p>If you'd like to see the command it is as follows:</p>
  
  <pre><code>exports.info =
  {
      name: "Ping",
      permission: 10,
      category: "User",
      about: "Makes the bot respond with pong, useful to see if the bot is working."
  };
  
  exports.run = function(msg)
  {
      msg.channel.send("Pong!");
  }
  </code></pre>
  
  <p>Any tips, reference, examples, or just plain spoon feeding is 100% welcome. Also, if you'd like to maybe share some better techniques for doing what I'm doing please let me know as I'm just a beginner with JS.</p>