text: // Initialize a new discord client
  const Discord = require('discord.js');
  const client = new Discord.Client();
  var mysql = require('mysql')
  
  
  const config = require('./config');
  client.config = config;
  
  let token = config.token;
  
  var con = mysql.createConnection({
      host: config.SQLhost,
      user: config.SQLuser,
      password: config.SQLpassword,
      database: config.SQLdatabase
  })
  
  
  
  
  // Require dependencies
  const fs = require('fs');
  const Enmap = require('enmap');
  //const CronJob = require('cron').CronJob;
  
  const helpers = require('./Modules/helpers');
  const { resourceLimits } = require('worker_threads');
  
  // Listen to all possible events
  fs.readdir("./Events/", (err, files) => {
      if (err) return console.error(err);
      files.forEach(file => {
          const event = require(`./Events/${file}`);
          let eventName = file.split(".")[0];
          client.on(eventName, event.bind(null, client));
      });
  });
  
  client.commands = new Enmap();
  
  // Register all available commands into the client
  helpers.getFiles('./Commands').forEach(file => {
      if (!file.endsWith(".js")) return;
  
      let props = require(file);
      let commandName = file.split("/");
      commandName = commandName[commandName.length - 1].split('.')[0];
  
      console.log(getTimeStamp() + `Attempting to load command ${commandName} from dir: ${file}`);
  
      client.commands.set(commandName, props);
  });
  
  console.log(getTimeStamp() + 'Commands loaded');
  console.log();
  
  
  /*async function getServerData() {
  
      con.connect(async function(err) {
          if (err) throw err;
          console.log('connected');
          con.query(`SELECT * FROM data `, async function(err, result, fields) {
              if (err) throw err;
              console.log("downloaded data");
              serverData = await result;
  
              const server_id = result[0].server_id;
              const channel_id = result[0].channel_id;
              const live_role_id = result[0].live_role_id;
              const streamer_role_id = result[0].streamer_role_id;
              const notification_role_id = result[0].notification_role_id;
  
              console.log(server_id + " " + channel_id + " " + live_role_id + " " + streamer_role_id + " " + notification_role_id)
          })
  
      })
  
  }*/
  
  
  function checkForActivity(presence, act) {
      //presence.activities.forEach(activity => { console.log(activity.type) });
      return presence.activities.some(activity => activity.type == act)
  
  }
  
  function returnActivity(presence, act) {
      return presence.activities.find(activity => activity.type == act)
  }
  
  function checkForRole(member, rid) {
      return member.roles.cache.some(role => role.id == rid);
  }
  
  function checkForGuild(presence, gid) {
      return presence.guild.id == gid;
  }
  
  function getTimeStamp() {
      var date = new Date;
      return "[" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "]";
  }
  
  
  client.on('presenceUpdate', async(oldPresence, newPresence) => {
  
      const debugActivity = "STREAMING";
      if (!newPresence.activities) return false;
      await newPresence.member.fetch(newPresence.member.id);
      console.log(getTimeStamp() + "Checking <" + newPresence.user.username + "> in <" + newPresence.guild.name + ">:");
      console.log();
      console.log(getTimeStamp() + "CheckForGuild:        " + checkForGuild(newPresence, "857617077133115443"))
      console.log(getTimeStamp() + "CheckForRole:         " + checkForRole(newPresence.member, "860232566690676758"))
      console.log(getTimeStamp() + "CheckForActivityNew:  " + checkForActivity(newPresence, debugActivity))
      console.log(getTimeStamp() + "CheckForActivityOld:  " + checkForActivity(oldPresence, debugActivity));
      console.log();
      if (checkForActivity(newPresence, debugActivity)) console.log(getTimeStamp() + returnActivity(newPresence, debugActivity).url);
      if (checkForActivity(oldPresence, debugActivity)) console.log(getTimeStamp() + returnActivity(oldPresence, debugActivity).url);
      if (checkForGuild(newPresence, "857617077133115443") && checkForRole(newPresence.member, "860232566690676758") && (checkForActivity(newPresence, debugActivity) || checkForActivity(oldPresence, debugActivity))) {
          newPresence.member.roles.cache.forEach(role => console.log(getTimeStamp() + role.name));
          if (checkForActivity(newPresence, debugActivity) && !checkForActivity(oldPresence, debugActivity)) {
  
              if (newPresence.user.id == "232191205700534275") {
                  console.log("It's Comp!");
                  console.log(getTimeStamp() + `${newPresence.user.username} started streaming at ${returnActivity(newPresence, debugActivity).url}`);
  
                  const channel = client.channels.cache.get("857650608268771408");
  
                  channel.send(`<@&860232720616259616> It is me! ${newPresence.user.username}! I am live!!! Tune in at ${returnActivity(newPresence, debugActivity).url}`).then(message => message.crosspost());
  
                  let role = newPresence.guild.roles.cache.find(role => role.id === '859934121661169674');
                  console.log('Adding live role');
                  newPresence.member.roles.add(role).catch(console.error);
              } else {
                  console.log(getTimeStamp() + `${newPresence.user.username} started streaming at ${returnActivity(newPresence, debugActivity).url}`);
  
                  const channel = client.channels.cache.get("857663909381144576");
  
                  channel.send(`<@&860232720616259616> ${newPresence.user.username} started streaming at ${returnActivity(newPresence, debugActivity).url}`);
  
                  let role = newPresence.guild.roles.cache.find(role => role.id === '859934121661169674');
                  console.log('Adding live role');
                  newPresence.member.roles.add(role).catch(console.error);
              }
  
          };
          if (!checkForActivity(newPresence, debugActivity) && checkForActivity(oldPresence, debugActivity)) {
  
              console.log(getTimeStamp() + `${newPresence.user.username} stopped streaming`);
              console.log();
  
              let role = newPresence.guild.roles.cache.find(role => role.id === '859934121661169674');
              console.log(getTimeStamp() + 'Removing live role');
              console.log();
              newPresence.member.roles.remove(role).catch(console.error);
          }
  
      }
  });
  
  
  
  client.login(token);
  
  
  
  client.on('ready', async() => {
  
      let guilds = client.guilds.cache.map(guild => guild.name)
  
      console.log(getTimeStamp() + `I'm on these servers:`);
      console.log(getTimeStamp() + guilds);
      console.log();
  
      console.log(getTimeStamp() + `I'm ready :)`);
      console.log();
  
  });