title: Discord.js ReferenceError: bot is not defined
body: <p>I am trying to create a bot, which will be given the role when user joins the server by link, but this doesn't work. 
  Error:</p>
  
  <pre><code>C:\DGhostsBot\bot.js:45
  bot.on("guildMemberAdd", (member) =&gt; {
  ^
  
  ReferenceError: bot is not defined
      at Object.&lt;anonymous&gt; (C:\DGhostsBot\bot.js:45:1)
      at Module._compile (internal/modules/cjs/loader.js:689:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
      at Module.load (internal/modules/cjs/loader.js:599:32)
      at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
      at Function.Module._load (internal/modules/cjs/loader.js:530:3)
      at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
      at startup (internal/bootstrap/node.js:283:19)
      at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
  </code></pre>
  
  <p>My code here:</p>
  
  <pre><code>const Discord = require('discord.js');
  
  const client = new Discord.Client();
  
  var prefix = "dg!"
  
  client.login(`**************************************************************`);
  
  client.on("message", (message) =&gt; {
      if(message.content == prefix + "test") {
          message.reply("just a command that is used for performance testing. Do not pay attention.");
       }
  });
  
  client.on("message", (message) =&gt; {
      if(message.content == prefix + "cake") {
          message.reply("here's your cake :3 :cake: ");
       }
  });
  
  client.on("message", (message) =&gt; {
      if(message.content == prefix + "help") {
          message.reply("it's in development");
  }     
  });
  
  client.on("message", (message) =&gt; {
      if(message.content == prefix + "kick") {
  if(message.member.roles.some(r=&gt;["Developer", "devadmin"].includes(r.name)) ) {
       const user = message.mentions.users.first();
      if (user) {
        const member = message.guild.member(user);
        if (member) {
         member.kick()
  }
  }
  } else {
   message.reply("!!!!ACCESS_DENIED!!!!").then(sentMessage =&gt; sentMessage.delete("delete"));
  
  }
  }     
  });
  
  
  bot.on("guildMemberAdd", (member) =&gt; {
  
      if (member.id == bot.user.id) {
          return;
      }
      let guild = member.guild
      guild.fetchInvites().then(invdat =&gt; {
          invdat.forEach((invite, key, map) =&gt; {
              console.log(invite.code)
              if (invite.code === "qQAkqFQ") {
                  return member.addRole(member.guild.roles.find(role =&gt; role.name === "Member"));
              }
          })
      })
  });
  </code></pre>
  
  <p>I check a lot of answers on the internet, but nothing of all this doesn't work.
  So, I do not know how to fix this error.</p>