Discord Jda - Invalid Member List

Discord JDA - Invalid Member List

I assume you're using a development version of the 4.2.0 release (4.1.1_102 and above)

In these versions, the new factory methods have been introduced to make people aware of the new discord API design. In the future, bots will be limited to cache members who connected to voice channels by default.

If all you need is the count of members you can just use Guild#getMemberCount! Otherwise:

The createDefault/createLight will only cache members connected to voice channels or owners of guilds (on first sight). To cache more members, you will have to enable the GUILD_MEMBERS intent in both the application dashboard for your bot and in JDA.

Sample Image

Now you can do something like this:

JDA api = JDABuilder.createDefault(token)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.build();

The GUILD_MEMBERS intent is needed because it enables the GUILD_MEMBER_REMOVE dispatch to tell the library to remove a member from the cache when they are kicked/banned/leave.

This setup will perform lazy loading, which means it will start with only voice members and add more members to the cache once they become active.

To load all members on startup you have to additionally enable member chunking:

JDABuilder.createDefault(token)
.setChunkingFilter(ChunkingFilter.ALL) // enable member chunking for all guilds
.setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.build();

You can also load them for individual guilds using Guild#loadMembers or Guild#findMembers.

I recommend to also read this JDA wiki article: Gateway Intents and Member Cache Policy.

JDA guild.getMembers() no longer getting all members, since few days ago

You will need to cache members to loop through them.
When using methods such as getMember() or getMemberById() unless its the owner of guild or the bot itself its null.

When using createLight() or createDefault() for building a JDA Member Caching and Member Chunking is disabled by default.

Things like User class can't be null, as it is provided by discord

For more info on caching all members read this

JDA getMembers() only returns users who wrote in the chat since the bot's startup?

The method you're using only returns the cached members, to get all the members you'll need to use Guild#loadMembers().

Read more about that here: https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/api/entities/Guild.html#loadMembers()

JDA Mentioned member - not working command

It seems like you didn't quite get the problems in your code.

final Member target = event.getMessage().getMentionedMembers().get(0);

This will throw an IndexOutOfBoundsException if your message doesn't include a mentioned member. Because in this case the list of getMentionedMembers() is empty. There is no object to access. get(0) can't get anything.

In order to fix this you have to check first if the list is empty or if the length is zero as Minn already proposed. If it is you can display a message stating, that they need to add an @username.

Cleaning up your code and restructuring it accordingly would help a lot I suppose. Please go over it and make sure to always check, if the needed data exists in the first place and if you really need it. Some things are only needed for a small number of cases, calling them on every message / command is not good practice.

For example, at the moment your bot tries to get the first mentioned member from EVERY message that is sent. This isn't necessary hence you only need it in case it is the kick command.

By the way, the SelfMember is the bot itself. In your code you are telling the user that they don't have the permission although the bot (and not necessarily the user) might lack it which could be confusing.

I didn't see it earlier: Your bot is receiving its own messages as well. You might want to check, if the author of a message is your / a bot before continuing.

In the end I would advice you to always try to understand the answer or advice that is given to you. Asking another question for the same problem isn't going to help you nor does it cast a good light on you and your attempt to learn.

Discord JDA getOnlineStatus() is not checking for online members on the server

You need to enable the GUILD_PRESENCES intent to keep track of the online status. Add this to your builder: enableIntents(GatewayIntent.GUILD_PRESENCES) and enable it in your application dashboard.



Related Topics



Leave a reply



Submit