'Discord onGuildMemberJoinEvent is not working

I have this problem with Discord JDA, and I'm completely frustrated about it. I hope you can help me. The problem is my console won't print a message when a user joins, and I absolutely don't know why it doesn't work.

import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

public class Events extends ListenerAdapter {

  @Override
  public void onGuildMemberJoin(GuildMemberJoinEvent event) {
    System.out.println("Ja moin");
    /**User user = event.getUser();
    Guild guild = event.getGuild();
    user.getAsMention();
    System.out.println("Der User: " + user + " ist auf den Server: " + guild);**/
  }
}

import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import de.jonathan.Events;
import javax.security.auth.login.LoginException;

public class Bot extends ListenerAdapter {
   public static void main(String[] args) throws LoginException {
        JDABuilder builder = new JDABuilder(AccountType.BOT);
        String token = "<My Token>";
        builder.setActivity(Activity.playing("HARIBOB"));
        builder.setStatus(OnlineStatus.DO_NOT_DISTURB);
        builder.setToken(token);

        builder.build();

        // Events
        builder.addEventListeners(new Events());
    }
}


Solution 1:[1]

The solution is / was i needed to enable the Intents on the Discord page. After this I needet to add the line:

.enableIntents(GatewayIntent.GUILD_MEMBERS)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan Schuder