Jda: Error using .getUser().isBot()

Created on 1 Oct 2017  路  8Comments  路  Source: DV8FromTheWorld/JDA

Hello guys !
Until now, I was using this lines :

Member author = event.getMember();
if(!author.getUser().isBot()) {...}

But today, I have this error on the author.getUser().isBot() function :

[Fatal] [JDA]: java.lang.NullPointerException
at MainBot.onGuildMessageReceived(...)

I was on JDA 3.0.0 and seeing that problem I updated to 3.3.0 but the problem still here.
Do you know why ? Can you help me ?

Thank a lot :)

Most helpful comment

It could have been an webhook message, as those don't have members

All 8 comments

From your code I can only assume that event is an instance of MessageReceivedEvent.
This event fires for every message you receive both guild and private channel. Members are only present for guilds and your use of them is rather bad.
To get the author user you should be using event.getUser() instead of event.getMember().getUser().

event is an instance of GuildMessageReceivedEvent , using the function :

public void onGuildMessageReceived(GuildMessageReceivedEvent event)

Do I have to use the onMessageReceived() function ?

From the provided information we cannot help you any further. Try debugging your code.

also update to the latest version. you can find it at the top of the Readme or inside of the release-page as small badge (its 3.3.1)

It could have been an webhook message, as those don't have members

@natanbc ooooh... that could be it! Being ashamed of not thinking about that myself :(

pat, yeah, he should check for isFake too to avoid running across webhooks.

This should instead be:

if (event.getUser().isBot() || event.getMessage().isWebhookMessage()) 
{...}
else
{
    Member author = event.getMember()
    ...
}

Webhook messages do not have Member objects.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YukioKeno picture YukioKeno  路  6Comments

Bastian picture Bastian  路  5Comments

MinnDevelopment picture MinnDevelopment  路  5Comments

Mas281 picture Mas281  路  3Comments

hitsu420 picture hitsu420  路  6Comments