discord-jda / JDA

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

onUserActivityStart doesn't detect activity #2723

Closed AdamJD01 closed 3 months ago

AdamJD01 commented 3 months ago

General Troubleshooting

Version of JDA

5.1.0

Expected Behaviour

I want onUserActivityStart to detect when a user is doing an activity (listening, playing, streaming etc) but it does nothing when my activity status gets updated for testing and doesn't even log a test message. My bot has the privileged intents enabled in the developer portal and the bot has the required permissions set in the server. I have everything enabled in the code just for testing. I've also tested other listeners such as onUserTyping as a sanity check and the other listeners work.

Code Example for Reproduction Steps

public class UserActivityListener extends ListenerAdapter
{
    @Override
    public void onUserActivityStart(@NotNull UserActivityStartEvent event)
    {
        super.onUserActivityStart(event);

        System.out.println("Test");
    }
}

Code for JDABuilder or DefaultShardManagerBuilder used

JDABuilder builder = JDABuilder.createDefault(Token.token)
  .enableIntents(EnumSet.allOf(GatewayIntent.class))
  .enableCache(EnumSet.allOf(CacheFlag.class))
  .setMemberCachePolicy(MemberCachePolicy.ALL)
  .setChunkingFilter(ChunkingFilter.ALL)
  .setAutoReconnect(true);

JDA api = builder.build();
api.addEventListener(new UserActivityListener());

Exception or Error

N/A
MinnDevelopment commented 3 months ago

I've just tested this with your exact code on 5.1.0 and had no issues detecting activity start events. Is your bot in the same server as the user you try to detect activity changes of? Has the bot finished loading before you change your activity? Is the user currently online, since activities do not show up for invisible users.

You can test activities by setting a custom status:

image

AdamJD01 commented 3 months ago

Yes to all those questions. Setting a custom status works but if I for example play a game that Discord recognizes and says I'm playing then it does nothing.

MinnDevelopment commented 3 months ago

Can you check your privacy settings, whether you actually share your activity with others?

User Settings:

image

Per-Guild Settings:

image

image

AdamJD01 commented 3 months ago

That was the issue... I had the share your activity status by default setting disabled. Thank you for your help. I feel rather dumb now lol