Skip to content

m-sterling/Java-DiscordRPC

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jitpack

Java-DiscordRPC

This library contains Java bindings for Discord's official RPC SDK using JNA.

This project provides binaries for linux-x86-64, win32-x86-64 and darwin.

If, on macOS, you get the following message which can be ignored: Error in LSRegisterURL: -10811

Documentation

You can see the official discord documentation in the API Documentation.
Alternatively you may visist the javadoc at jitpack.

Examples

import club.minnced.discord.rpc.*;

public class Main {
    public static void main(String[] args) {
        DiscordRPC lib = DiscordRPC.INSTANCE;
        String applicationId = "";
        String steamId = "";
        DiscordEventHandlers handlers = new DiscordEventHandlers();
        handlers.ready = () -> System.out.println("Ready!");
        lib.Discord_Initialize(applicationId, handlers, true, steamId);
        DiscordRichPresence presence = new DiscordRichPresence();
        presence.startTimestamp = System.currentTimeMillis() / 1000; // epoch second
        presence.details = "Testing RPC";
        lib.Discord_UpdatePresence(presence);
        // in a worker thread
        new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                lib.Discord_RunCallbacks();
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException ignored) {}
            }
        }, "RPC-Callback-Handler").start();
    }
}

Note: To reveal this presence you have to start a window for your application.

License

Java-DiscordRPC is licensed under the Apache 2.0 License. The base DiscordRPC is licensed under the MIT license.

Contributing

Find something that is lacking? Fork the project and pull request!

Packages

No packages published

Languages

  • Java 100.0%