discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.35k stars 734 forks source link

Activity is null #1317

Closed Th3Ph4nt0m closed 4 years ago

Th3Ph4nt0m commented 4 years ago

General Troubleshooting

Bug Report

Sometimes the current activity of a member is detected, sometimes don't.

Expected Behavior

The activity should be detected.

Code Example or Reproduction Steps

    if (member.getActivities().size() >= 1) {
        return member.getActivities().get(0).getName();

Code for JDABuilder or DefaultShardManagerBuilder Used

        this.jda = JDABuilder.createDefault("Token")
                .setAutoReconnect(true)
                .setStatus(OnlineStatus.ONLINE)
                .setActivity(Activity.watching("activity"))
                .enableIntents(GatewayIntent.GUILD_PRESENCES)
                .enableCache(EnumSet.of(CacheFlag.ACTIVITY))
                .build();

Exception or Error

N/A

MinnDevelopment commented 4 years ago

You are using the default member cache policy MemberCachePolicy.VOICE so the activities cannot be tracked. In order to track activities for members, you have to cache the members.

You can use setMemberCachePolicy(MemberCachePolicy.ONLINE) to only cache members who are currently online.

Th3Ph4nt0m commented 4 years ago

Worked, thanks for the quick help!