title: Exporting/importing in node.js / discord.js
body: <p>I am currently making a discord bot with discord.js and because I haven't programmed without an html file before I find using several js-files quite difficult. At first i thought using imports and exports was gonna work, but it isn't supported in Node yet. I did some snooping around and this is what i decided to do:</p>
  
  <h3>Index.js</h3>
  
  <pre><code>const commandFunctions = require('./commands.js')();
  const botconfig = require('./botconfig.json');
  
  bot.on('message', async message =&gt; {
      if (message.author.bot) { return; }
      if (message.channel.type === 'dm') { return; }
  
      messageArray = message.content.split(' ');
      cmd = messageArray[0];
      arg = messageArray.slice(1);
  
      if (cmd.charAt(0) === prefix) {
          checkCommands(message);
      } else {
          checkForWord(message);
      }
  });
  
  function checkCommands(message) {
      botconfig.commands.forEach(command =&gt; {
          if (arg === command) {
              commandFunctions.ping();
          }
      });
  }
  </code></pre>
  
  <h3>commands.js</h3>
  
  <pre><code>module.exports = function() {
      this.botinfo = function(message, bot) {
          let bicon = bot.user.displayAvatarURL;
          let botembed = new Discord.RichEmbed()
          .setColor('#DE8D9C')
          .setThumbnail(bicon)
          .addField('Bot Name', bot.user.username)
          .addField('Description', 'Inject the memes into my bloodstream')
          .addField('Created On', bot.user.createdAt.toDateString());
          return message.channel.send(botembed);
      } 
  
      this.roll = function(message) {
          let roll = Math.floor(Math.random() * 6) + 1;
          return message.channel.send(`${message.author.username} rolled a ${roll}`);
      }
  
      this.ping = function() {
          return message.channel.send('pong');
      }
  }
  </code></pre>
  
  <h3>botconfig.json</h3>
  
  <pre><code>"prefix": "+",
  "commands": [
       "botinfo",
       "roll",
       "ping"
  ]
  </code></pre>
  
  <p>My goal would be to make the code adaptable by just having to add a word to the json-file and a function that is connected to it in the commands.js. In the checkCommand function it should also trigger the function with the same name as the command, right now i've set it to trigger ping no matter what command I use, as I had some trouble with the arguments. Problem is the command-function is not being triggered at all, pretty sure that the checkCommand function is where it goes wrong.</p>