JnCrMx / discord-game-sdk4j

Java bindings for Discord's Game SDK
MIT License
114 stars 23 forks source link

Branch: `java-impl`, `activity.setType(ActivityType.LISTENING);` not working? #67

Closed CodeByAidan closed 1 year ago

CodeByAidan commented 1 year ago

Description

When running my application with the provided code, the Discord Rich Presence displays "Playing a game" instead of "Listening to ___" 😞 .

Steps to Reproduce

  1. Run the application with the provided code.
  2. Check the Discord Rich Presence.

Expected Behavior

The Discord Rich Presence should display "Listening to ___".

image

Actual Behavior

The Discord Rich Presence shows "Playing a game" instead of "Listening to ___".

image

Environment

Code

package org.spotify_podcast_rpc;

import de.jcm.discordgamesdk.Core;
import de.jcm.discordgamesdk.CreateParams;
import de.jcm.discordgamesdk.activity.Activity;
import de.jcm.discordgamesdk.activity.ActivityType;

import java.io.IOException;
import java.time.Instant;

public class DiscordSpotifyRPC {

    public static void main(String[] args) throws IOException {
        // Set parameters for the Core
        try (CreateParams params = new CreateParams()) {
            params.setClientID(1134114693468934164L);
            params.setFlags(CreateParams.getDefaultFlags());
            // Create the Core
            try (Core core = new Core(params)) {
                // Create the Activity
                try (Activity activity = new Activity()) {
                    activity.setDetails("Listening to Spotify");
                    activity.setState("Song/Podcast Name");

                    // Set the activity type to "Listening"
                    activity.setType(ActivityType.LISTENING);

                    // Setting a start time causes an "elapsed" field to appear
                    activity.timestamps().setStart(Instant.now());

                    // Make a "cool" image show up
                    activity.assets().setLargeImage("test");

                    // Setting a join secret and a party ID causes an "Ask to Join" button to appear
                    activity.party().setID("Party!");
                    activity.secrets().setJoinSecret("Join!");

                    // Finally, update the current activity to our activity
                    core.activityManager().updateActivity(activity);
                }

                // Run callbacks until the application is terminated
                while (!Thread.interrupted()) {
                    core.runCallbacks();
                }
            }
        }
    }
}
JnCrMx commented 1 year ago

Discord currently does not support specifying the type of the activity. This field is only used for event handlers and will be ignored when setting an activity through the Game SDK.

See JavaDoc for Acitivity#setType(ActivityType): https://github.com/JnCrMx/discord-game-sdk4j/blob/9cfd70a72c4393c292ea5b037426d5f24c6e434f/src/main/java/de/jcm/discordgamesdk/activity/Activity.java#L96

And from the SDK documentation (https://discord.com/developers/docs/game-sdk/activities#data-models-activitytype-enum):

ActivityType is strictly for the purpose of handling events that you receive from Discord; though the SDK/our API will not reject a payload with an ActivityType sent, it will be discarded and will not change anything in the client.