Skip to content

Why is Member null when using Guild.getMemberById(...)? #1599

Discussion options

You must be logged in to vote

When using methods such as getMember() or getMemberById(String) there's a possibility that the returned Member is null.
There can be many reasons, but most of the time the cause is that a Member isn't cached (yet).

When using createLight(String) or createDefault(String) for building a JDA/ShardManager instance JDA will disable Member Caching and Member Chunking.
This has the side-effect that JDA doesn't "know" a member yet and therefore returns null since a Member is nullable.

There are several options that you can do instead:

  • If you get the member of a Message-based event such as GuildMessageReceivedEvent, use getAuthor() instead as this returns a User object which won't be null.
  • Use re…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by DV8FromTheWorld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1595 on April 16, 2021 17:20.