text: require("dotenv").config()
  const constants = require('./constants');
  const { handleError } = require('./errors');
  const Discord = require("discord.js")
  const client = new Discord.Client({retryLimit: constants.RETRY_LIMIT})
  const { isSignup, processSignUpCommand } = require('./signup');
  const { isHostCommand, processHostCommand } = require('./host');
  
  client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`)
  })
  
  client.on("message", (msg) => {
    if (msg.author.bot || !msg.channel.name) {
      return;
    }
    try {
      if (isHostCommand(msg)) {
        processHostCommand(msg);
      } else if (isSignup(msg)) {
        processSignUpCommand(msg);
      }
    } catch (error) {
      handleError(msg, error);
    }
  })
  
  client.on("guildMemberUpdate", (oldMember, newMember) => {
    newMember.roles.cache.each((role) => {
      if (role.name === constants.VALIDATED_ROLE) {
        let hadRoleBefore = false;
        oldMember.roles.cache.each((role) => {
          if (role.name === constants.VALIDATED_ROLE) {
            hadRoleBefore = true;
          }
        });
        if (!hadRoleBefore) {
          let generalChannel = newMember.guild.channels.cache.find(channel => channel.name === constants.GENERAL_CHANNEL);
          generalChannel.send(`${newMember.toString()} Congratulations on passing gear verification and fully joining Mazcab Academy!
  
  First of all head to <#585510907678031907> and assign yourself a role based on your experience.
  
  After assigning yourself a role you can sign up for our daily raids in <#510107867597111317> using the format found in pinned messages there. You can check if there are available spots and who you will be raiding with in <#510107893874294794>. If the list is full feel free to sign up anyways and you will be put on backup list in case someone doesn't show up.
  
  Hosts will usually start inviting ~30 mins before the raid. You have to be present and ask for invite in discord at least ~10 mins before the raid starts or you risk being replaced. Roles are posted before the raid in <#622837797832884234>.
  
  After the raid you can check out <#510111127800381463> for feedback posted by host and <#530836159127879723> for feedback posted by your fellow raiders.
  
  If you are new to raids or want to learn new roles feel free to look at <#508322140744056833> and <#508322159937191960> or one of the role specific guides.
  
  Feel free to ping an <@&508330407226376192> or <@&506480937727426562> if you have any questions.`, { "allowedMentions": { "users": [newMember.id] } });
        }
      }
    });
  })
  
  client.login(process.env.BOT_TOKEN)
  