Im trying to make a bot that sends a pm when someone joins a server, and then assigns a role based on reply to said Pm.
This is the following code i have so far for onMessageRecieved, issue is that user.getMutualGuilds() returns an empty list even though they are part of the same server as the bot.
@Override
public void onMessageReceived(MessageReceivedEvent event) {
String DmRecieved = event.getMessage().getContentRaw();
User user = event.getAuthor();
boolean isBot = user.isBot();
boolean startsWithAU = DmRecieved.toUpperCase().startsWith("AU", 0);
boolean messageTooLong = DmRecieved.length() > 8;
if (event.getMessage().getContentRaw().isEmpty()) return;
if (isBot) return;
if (!startsWithAU || messageTooLong) {
user.openPrivateChannel().queue((chanel1 ->
chanel1.sendMessage("Not valid AU ID, please try again.").queue()));
} else {
List<Guild> guilds = user.getMutualGuilds();
System.out.println(guilds);
}
}
I found the fix. The members needed to be cached in memory this was done by adding the following line to the JDA:
jda.setMemberCachePolicy(member -> true);