Open JnCrMx opened 2 years ago
The ActivityExample does not use UserManager.getCurrentUser()
.
Could you please provide part of your code, so I have a chance to replicate this issue?
Yes, I will send the whole thing.
import de.jcm.discordgamesdk.Core;
import de.jcm.discordgamesdk.CreateParams;
import de.jcm.discordgamesdk.activity.Activity;
import java.io.File;
import java.io.IOException;
import java.time.Instant;
public class Discord {
public static void main(String[] args) throws IOException{
File discordLibrary = DownloadNativeLibrary.downloadDiscordLibrary();
if(discordLibrary == null){
System.out.println("Error downloading Discord SDK. Could not initialize Discord RP.");
return;
}
Core.init(discordLibrary);
try(CreateParams params = new CreateParams()){
try(Core core = new Core(params)){
//System.out.println(core.userManager().getUser);
params.setClientID(1006247841448071269L);
params.setFlags(CreateParams.getDefaultFlags());
try(Activity activity = new Activity()) {
activity.setDetails("Running an example");
activity.setState("and having fun");
// Setting a start time causes an "elapsed" field to appear
activity.timestamps().setStart(Instant.now());
// We are in a party with 10 out of 100 people.
activity.party().size().setMaxSize(100);
activity.party().size().setCurrentSize(10);
// Make a "cool" image show up
activity.assets().setLargeImage("discord");
activity.assets().setSmallImage("discord");
// 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);
}
while(true)
{
core.runCallbacks();
try
{
// Sleep a bit to save CPU
Thread.sleep(16);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}
}
I coppied the AcitivityExample
The code you sent does not call UserManager.getCurrentUser()
directly. However, your stracktrace contains a direct call from Discord.main
to UserManager.getCurrentUser()
.
One of them is probably not correct.
The code you sent does not call
UserManager.getCurrentUser()
directly. However, your stracktrace contains a direct call fromDiscord.main
toUserManager.getCurrentUser()
. One of them is probably not correct.
I used core.userManager().getCurrentUser()
but I get this error:
[ERROR] Failed to configure networking: ResponseError { code: TransactionAborted, message: "Transaction was aborted" }
Exception in thread "main" de.jcm.discordgamesdk.GameSDKException: Game SDK operation failed: NOT_FOUND
at de.jcm.discordgamesdk.UserManager.getCurrentUser(UserManager.java:75)
at Discord.main(Discord.java:25)
here is the current code in Discord.java
import de.jcm.discordgamesdk.Core;
import de.jcm.discordgamesdk.CreateParams;
import de.jcm.discordgamesdk.UserManager;
import de.jcm.discordgamesdk.activity.Activity;
import java.io.File;
import java.io.IOException;
import java.time.Instant;
public class Discord {
public static void main(String[] args) throws IOException{
File discordLibrary = DownloadNativeLibrary.downloadDiscordLibrary();
if(discordLibrary == null){
System.out.println("Error downloading Discord SDK. Could not initialize Discord RP.");
return;
}
Core.init(discordLibrary);
try(CreateParams params = new CreateParams()){
try(Core core = new Core(params)){
params.setClientID(1006247841448071269L);
params.setFlags(CreateParams.getDefaultFlags());
try(Activity activity = new Activity()) {
System.out.println(core.userManager().getCurrentUser());
activity.setDetails("Running an example");
activity.setState("and having fun");
// Setting a start time causes an "elapsed" field to appear
activity.timestamps().setStart(Instant.now());
// We are in a party with 10 out of 100 people.
activity.party().size().setMaxSize(100);
activity.party().size().setCurrentSize(10);
// Make a "cool" image show up
activity.assets().setLargeImage("discord");
activity.assets().setSmallImage("discord");
// 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);
}
while(true)
{
core.runCallbacks();
try
{
// Sleep a bit to save CPU
Thread.sleep(16);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}
}
First of all, please set all the required parameters in CreateParams
before creating the Core
.
Secondly, getCurrentUser()
only works after the first onCurrentUserUpdate()
.
This is what causes the exception. NOT_FOUND
also seems to be the correct result for this case.
Please refer to the JavaDoc for more information about that. There is also a section about it in the documentation provided by Discord: https://discord.com/developers/docs/game-sdk/users#getcurrentuser
Before calling this function, you'll need to wait for the OnCurrentUserUpdate callback to fire after instantiating the User manager.
With this library, the User manager is instantiated automatically, so you only need to wait for the onCurrentUserUpdate()
.
I am also having this issue. I don't think the user is getting set properly.
Originally posted by @CG-Spectre in https://github.com/JnCrMx/discord-game-sdk4j/issues/32#issuecomment-1232295599