I'm trying to write a discord bot using JDA, and while I can get the presence of the bot fairly easily, I cannot get the presence of a selected user. An example use case for this might be the user typing in a command like !game
and then the bot sends a message telling the user what game they're playing. As far as I know, the bot cannot get the user's game activity without getting the user's presence, and I do not see a way to do so. If I missed it in the documentation, please link the method/class.
After a bunch of digging and documentation reading, I have come to a solution. There is no way to get a presence like I was thinking, but since my original intent was to get the game activity, this solution works. First, the bot must have guild presence permissions granted through the developer portal. Then we need to include the line jdaBuilder.enableIntents(GatewayIntent.GUILD_PRESENCES);
before we call the build method in our main method. Finally, to get member activities, we need to include jdaBuilder.enableCache(CacheFlag.ACTIVITY);
. This lets us use the member.getActivities()
method. Generally speaking, getting data associated with specific users requires enabling guild presences.