title: problem with voiceStateUpdate in JavaScript
body: <p>I'm trying to get this discord bot work. The idea is simple, make the bot send a notification when someone joins in the voice chat.
  Im making this on Atom, the error i got is this one:</p>
  
  <pre><code>TypeError: Cannot read property 'send' of undefined
  at Client.client.on (C:\Users\Franco\Desktop\bot\bot.js:15:20)
  at emitTwo (events.js:126:13)
  at Client.emit (events.js:214:7)
  at VoiceStateUpdateHandler.handle (C:\Users\Franco\Desktop\bot\node_modules\discord.js\src\client\websocket\packets\handlers\VoiceStateUpdate.js:39:16)
  at WebSocketPacketManager.handle (C:\Users\Franco\Desktop\bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
  at WebSocketConnection.onPacket (C:\Users\Franco\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
  at WebSocketConnection.onMessage (C:\Users\Franco\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
  at WebSocket.onMessage (C:\Users\Franco\Desktop\bot\node_modules\ws\lib\event-target.js:120:16)
  at emitOne (events.js:116:13)
  at WebSocket.emit (events.js:211:7)
  </code></pre>
  
  <p>the code attempt:</p>
  
  <pre><code>client.on("message", function(message) {
    client.on('voiceStateUpdate', (oldMember, newMember) =&gt; {
      console.log('lol');
      let newUserChannel = newMember.voiceChannel
      let oldUserChannel = oldMember.voiceChannel
      var channel = client.channels.get('353996293154144259');
      if(oldUserChannel === 353996293154144260 &amp;&amp; newUserChannel !== 489674797261783041) {
        channel.send('has joined a voice channel');
        // User Joins a voice channel
      } else if(newUserChannel === 489674797261783041){
         channel.send('has left a voice channel');
      // User leaves a voice channel
      }
    })
  })
  </code></pre>
  
  <p>The console.log is just for testing if <code>voiceStateUpdate</code> is working.</p>
  
  <p>When I try to run it I get this error:</p>
  
  <blockquote>
    <p>"TypeError: Cannot read property 'send' of undefined"</p>
  </blockquote>
  
  <h1>As i understand the error is because <code>.send</code> function is undefined</h1>
  
  <p>i got almost everything from here:</p>
  
  <ul>
  <li><a href="https://www.reddit.com/r/discordapp/comments/6p85uf/discordjs_any_way_to_detect_when_someone_enter_a/" rel="nofollow noreferrer">https://www.reddit.com/r/discordapp/comments/6p85uf/discordjs_any_way_to_detect_when_someone_enter_a/</a></li>
  <li><a href="https://discord.js.org/#/docs/main/stable/general/welcome" rel="nofollow noreferrer">https://discord.js.org/#/docs/main/stable/general/welcome</a></li>
  </ul>
  
  <p>Everything I've tried:</p>
  
  <ul>
  <li><p>Add <code>client.on("message", function(message) {</code></p></li>
  <li><p>Edit <code>.send</code> to <code>.message</code> and <code>.sendMessage</code></p></li>
  <li><p>try to define .send</p></li>
  <li><p>change client.channels.get to lient.channelid.get</p></li>
  <li><p>Change/delete <code>var channel = client.channels.get('353996293154144259');</code></p></li>
  <li><p>Move <code>client.on('voiceStateUpdate', (oldMember, newMember) =&gt; {</code> out of <code>client.on("message", function(message) {</code> When i do that i got another error</p></li>
  </ul>
  
  <blockquote>
    <p>"Second error i got when i move client.on out: "(node:18196) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added. Use emitter.setMaxListeners() to increase limit"</p>
  </blockquote>
  
  <p>Maybe some useless info:</p>
  
  <ul>
  <li><p>353996293154144259 = id of General chat on discord server</p></li>
  <li><p>353996293154144260 = id of the first voice chat</p></li>
  <li><p>489674797261783041 = id of the second voice chat</p></li>
  </ul>
  
  <h1>UPDATE</h1>
  
  <p>Okay, i solved part of the problem, i need use <code>message.channel.send('has joined a voice channel');</code> instead of <code>channel.send('has joined a voice channel');</code> But i can't make it work as i want.</p>
  
  <hr>
  
  <p>Special thanks for YakovL. He helps me to make this post more complete and better.</p>