title: Using Node.js and I want to code a welcome bot for my server
body: <p>I'm working in MacOS with node.js and I have a bot that sends messages in a channel but I want to get rid of MEE6 and only use my bot. So I want to add a welcome action when people join my server. I've looked on google for coding examples but none of the examples work with the current node.js build. I would like to send a welcome message in a dedicated channel. I want the bot to use the user's username in the message and give a message when someone joins and when someone leaves. Here is my current code.</p>
  <pre><code>// Require the necessary discord.js classes
  const { Client, GatewayIntentBits } = require('discord.js');
  const { token } = require('./config.json');
  
  
  // Create a new client instance
  const client = new Client({ intents: [GatewayIntentBits.Guilds] });
  
  
  // When the client is ready, run this code (only once)
  client.once('ready', () =&gt; {
  
    client.on('guildMemberAdd', guildMember =&gt; {
      guildMember.guild.channels.cache.get('1010768161349587035').send(`**Welcome to the discord server, &lt;@${guildMember.user.id}&gt;!**`);
  });
  
  const randomMsg = ['message 1', 'message 2', 'message 3']
  
  const random = (min, max) =&gt; {
    return Math.floor(Math.random() * (max - min + 1) + min);
  }
  
  const sendRandomMsg = () =&gt; {
  
      client.channels.cache.get('1006941719666905089').send(randomMsg[random(0, randomMsg.length - 1)]);
  }
  
  setInterval(function(){ sendRandomMsg() }, 1000 * 60 );
  
  });
  console.log('(。··)_且');
  
  // Login to Discord with your client's token
  client.login(token);
  </code></pre>
  <p>I tried adding more intents from this example:</p>
  <pre><code>const client = new Client({ 
      intents: [
          Intents.FLAGS.GUILDS,
          Intents.FLAGS.GUILD_MESSAGES,
          Intents.FLAGS.GUILD_MEMBERS //also enable in discord developer portal
      ] 
  })
  </code></pre>
  <p>But when I add these intents as they are coded, it returns an error saying &quot;Intents&quot; isn't defined. I added SERVER MEMBERS INTENT on the discord developer portal. But when I join the server with my alt account nothing happens in the welcome channel. Any help is appreciated.</p>