const Discord = require('discord.js');

const utils = require('./lib/utils.js');

const config = require('./config.json');
const pasta = require('./pasta.json');

const client = new Discord.Client();

client.on('ready', () => {
  console.log(`Bot started! (${client.user.username})`);
});

client.on('message', msg => {
  if (msg.author === client.user) return;
  if (!msg.content.startsWith(config.prefix)) return;
  
  let command = msg.content.substr(config.prefix.length).split(' ')[0];
  let args = msg.content.split(' ').slice(1);
  let usertype = 'regular';

  let errMesg = 'archbot: command not found: ' + command;

  if (typeof (pasta[command]) !== 'undefined') {
    let regPasta = pasta[command];
    if (Object.prototype.toString.call(pasta[command]) === '[object Object]') {
      msg.channel.send(pasta[command]);
    } else if (Object.prototype.toString.call(pasta[command]) === '[object Array]') {
      regPasta.forEach(function (part) {
        msg.channel.send(part);
      });
    }
    return;
  }

  if (command === 'sudo') {
    if (!msg.member.roles.exists('id', config.sudoersRole)) {
      msg.channel.send('<@' + msg.author.id + '> is not in the sudoers file. This incident will be reported.');
      client.channels.get(config.sudoLogChannel).send('<@' + msg.author.id + '> is getting coal for Christmas.');
      return;
    } else {
      usertype = 'sudoer';
      command = args[0];
      args = args.slice(1);
      errMesg = 'archbot: sudo: command not found: ' + command;
    }
  }

  try {
    let cmdFile = require('./commands/' + command);
    cmdFile.run(msg, args, usertype);
  } catch (e) {
    msg.channel.send(errMesg);
    console.log(e);
  }
});

client.on('guildMemberAdd', member => {
  client.channels.get(config.joinLogChannel).send('Joined: <@' + member.id + '>');
});

client.login(config.token).then(function () {
  client.user.setGame('');
  /* if you want the bot not to have a "Playing..." message, you have to
   * pass an empty parameter and wait for the bot to leave the channel before restarting */
});
@@ -409,18 +409,16 @@
 return;%0A
-  
 %0A  let c
@@ -790,168 +790,862 @@
     
-msg.channel.send(pasta%5Bcommand%5D);%0A    %7D else if (Object.prototype.toString.call(pasta%5Bcommand%5D) === '%5Bobject Array%5D') %7B%0A      regPasta.forEach(function (part) %7B
+if (args.length !== 0) %7B%0A        let txtPasta = regPasta.embed.description;%0A        for (let x in args) %7B%0A          let find = args%5Bx%5D.split('/')%5B0%5D;%0A          let replace = args%5Bx%5D.split('/')%5B1%5D;%0A          let regex = new RegExp(find, 'gi');%0A          txtPasta = txtPasta.replace(regex, replace);%0A        %7D%0A        regPasta.embed.description = txtPasta;%0A      %7D%0A      msg.channel.send(regPasta);%0A    %7D else if (Object.prototype.toString.call(pasta%5Bcommand%5D) === '%5Bobject Array%5D') %7B%0A      regPasta.forEach(function (embPasta) %7B%0A        if (args.length !== 0) %7B%0A          let txtPasta = embPasta.embed.description;%0A          for (let x in args) %7B%0A            let regex = new RegExp(args%5Bx%5D.split('/')%5B0%5D, 'gi');%0A            txtPasta = txtPasta.replace(regex, args%5Bx%5D.split('/')%5B1%5D);%0A            embPasta.embed.description = txtPasta;%0A          %7D%0A        %7D
 %0A   
@@ -1670,12 +1670,16 @@
 end(
-part
+embPasta
 );%0A 
@@ -2747,12 +2747,13 @@
 rting */%0A%7D);
+%0A

Replace works, but it *replaces it in the main array* for some reason