title: Count the number of messages for specific user jda
body: <p>I have found a lot of tutorials on how to count the number of messages for a specific user but all of them was for discord.py. Now I need to do it but for discord jda. I have tried a lot of different methods but non worked. Any help?</p>
  <p>okay this is what I tried so far. Even though I know it is so wrong anyways:</p>
  <pre><code>public class ExpSystem extends ListenerAdapter {
  
      HashMap&lt;User, Integer&gt; playerXp = new HashMap&lt;&gt;();
      HashMap&lt;User, Integer&gt; playerMessages = new HashMap&lt;&gt;();
      HashMap&lt;User, Integer&gt; playerTimer = new HashMap&lt;&gt;();
      int counter = 0;
      public void onGuildMessageReceived(GuildMessageReceivedEvent event){
          String[] args = event.getMessage().getContentRaw().split(&quot; &quot;);
          String command = args[0];
          System.out.println(event.getMessage());
  
  
  
          if(command.equalsIgnoreCase(&quot;tr!&quot; + &quot;xp&quot;)){
              System.out.println(&quot;command&quot;);
              if (canGetXp(event.getMember().getUser())){
                  if (event.getMember().getUser() == event.getMessage().getMember().getUser()){
                      counter ++;
                      setPlayerMessages(event.getMember().getUser(),counter);
                      System.out.println(&quot;cangetxp&quot;);
                      randXp(event.getMember().getUser());
                      setPlayerTime(event.getMember().getUser(), 3);
                      event.getChannel().sendMessage(&quot;You have &quot; + getPlayerXp(event.getMember().getUser()) + &quot; xp&quot;+ &quot;And &quot; + getPlayerMessages(event.getMember().getUser()) + &quot; Messages&quot;).queue();
                  }
  
              }else {
                  event.getChannel().sendMessage(&quot;You have &quot; + getPlayerXp(event.getMember().getUser()) + &quot; xp&quot; + &quot;And &quot; + getPlayerMessages(event.getMember().getUser()) + &quot; Messages&quot;).queue();
              }
  
          }
  
  
      }
  
      private int getPlayerXp(User member){
          return playerXp.get(member);
      }
  
      private int getPlayerMessages(User member){
          return playerMessages.get(member);
      }
  
      private void setPlayerXp(User member, int num){
          playerXp.put(member, num);
      }
  
      private void setPlayerMessages(User member, int num){
          playerXp.put(member, num);
      }
  
      private int getPlayerTime(User member){
          return playerTimer.get(member);
      }
  
      private void setPlayerTime(User member, int num){
          playerTimer.put(member,num);
      }
  
      private void randXp(User member){
          Random r = new Random();
          if (!playerXp.containsKey(member)){
            setPlayerXp(member, 0);
          }
          setPlayerXp(member, getPlayerXp(member) + r.nextInt(25));
      }
  
      private boolean canGetXp(User member){
          if(!playerTimer.containsKey(member)){
              return true;
          }
          return false;
      }
  
      public void startTimer(){
          System.out.println(&quot;TIMER STARTED&quot;);
          Timer timer = new Timer();
          TimerTask task = new TimerTask() {
              @Override
              public void run() {
                  for (User member : playerTimer.keySet()){
  
                      setPlayerTime(member,getPlayerTime(member) - 1);
                      if (getPlayerTime(member) == 0){
                          playerTimer.remove(member);
                      }
                  }
              }
          };
          timer.schedule(task,1000,1000);
      }
  
  
  
  }
  </code></pre>
  <p>My goal here is to gain xp when you send messages. But I always get:</p>
  <pre><code>[JDA MainWS-ReadThread] ERROR JDA - One of the EventListeners had an uncaught exception
  java.lang.NullPointerException: Cannot invoke &quot;java.lang.Integer.intValue()&quot; because the return value of &quot;java.util.HashMap.get(Object)&quot; is null
      at ExpSystem.getPlayerMessages(ExpSystem.java:50)
      at ExpSystem.onGuildMessageReceived(ExpSystem.java:33)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:405)
      at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
      at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:88)
      at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:70)
      at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:149)
      at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:97)
      at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
      at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:952)
      at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:839)
      at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:817)
      at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:990)
      at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:385)
      at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:276)
      at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:996)
      at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:755)
      at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
      at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
      at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
  </code></pre>
  <p><strong>EDIT</strong>:
  I have replaced  <code>playerXp.put(member, num);</code>
  to  <code>platerMessages.put(member, num);</code> in the <code>setPlayerMessages</code> method.
  But now the counter of all the users are the same, so it gives them the same number of messages. Is there any way I can Fix that?</p>