Lachee / discord-rpc-csharp

C# custom implementation for Discord Rich Presence. Not deprecated and still available!
MIT License
560 stars 94 forks source link

Set Presence in VB.NET #140

Closed PIN0L33KZ closed 3 years ago

PIN0L33KZ commented 3 years ago

Hi guys, I have a quick question. How do I set the Rich Presence in VB.NET?

I use the Library for my VB.NET Project and I can setup the Client with the ID and I can Initialize it. But all it sends to Discord Is just the Title of the Application, but how i can set up the Client correctly to send details, assets etc.?

Really appreciate your answers :)

discord rpc

Lachee commented 3 years ago

I dont actively support dead languages. However, it is in theory possible to use this library with VB.NET. Simple send a SetPresence and give it an appropriate RichPresence object as per the example.

Obviously, you will need to convert the C# example into VB.NET, but that shouldn't be too hard.

    //Set the rich presence
    //Call this as many times as you want and anywhere in your code.
    client.SetPresence(new RichPresence()
    {
        Details = "Example Project",
        State = "csharp example",
        Assets = new Assets()
        {
            LargeImageKey = "image_large",
            LargeImageText = "Lachee's Discord IPC Library",
            SmallImageKey = "image_small"
        }
    }); 
PIN0L33KZ commented 3 years ago

Thank you very much :) You helped me out. Here is my code for later readers. ^^ It’s a bit bigger, but it do what it’s supposed to.

        'Client
        Dim client As New DiscordRpcClient("YOUR_APPLICATION_ID") 'API KEY
        client.Initialize()

        'Timestamp (Unix Epoch)
        Dim unixtime As ULong = (Date.UtcNow - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds
        Dim rpctimestamps As New Timestamps
        rpctimestamps.StartUnixMilliseconds = unixtime

        'Assets
        Dim rpcassets As New Assets
        rpcassets.LargeImageKey = "large"
        rpcassets.SmallImageKey = "small"
        rpcassets.LargeImageText = "Minecraft Server Tools"
        rpcassets.SmallImageText = "editing..."

        'Final RPC
        Dim rpc As New RichPresence
        rpc.Details = "🟢 Server is Online"
        rpc.State = "Editing the Server"
        rpc.Assets = rpcassets
        rpc.Timestamps = rpctimestamps

        client.SetPresence(rpc)

Final Result: discord rpc -2