I have a Problem with Discord4Js MemberJoinEvent

292 Views Asked by At

I just started programming a new Discord bot for myself to see what I am able to create. Currently, I'm working on an Autorole feature but I just don't get why the Bot doesn't get triggered by a MemberJoinEvent. Here is my code:

gateway.getEventDispatcher().on(MemberJoinEvent.class).subscribe(memberJoinEvent -> {
       final Member member = memberJoinEvent.getMember();            
       System.out.println(member.toString());
});
2

There are 2 best solutions below

0
leguan On BEST ANSWER

I found the problem! I didnt know that discord changed something in their developer portal. Also I used my old project so I didnt notice it. You have to manualy enable it in the developer portal, that the bot can access member information. A screenshot of the location to enable the gateway feature

1
Patrick Brielmayer On

In addition to leguans answer, I also had to request the gateway intents as well!

GatewayDiscordClient gatewayDiscordClient() {
    return discordClient()
        .gateway()
        .setEnabledIntents(IntentSet.all())
        .login()
        .block();
}

https://docs.discord4j.com/migrating-from-v3-1-to-v3-2/#gateway-intents