discord / discord-rpc

https://discordapp.com/developers
MIT License
1.06k stars 330 forks source link

Is there a way to update only one parameter? #355

Closed Iamlel closed 2 years ago

Iamlel commented 2 years ago

Hello, I am trying to update the state activity when someone hits a button in my app. I couldn't find anything on the docs for updating, so I tried setting the activity again, but it removes everything else. Is there a good way of only updating 1 parameter, or do i just save all the other parameters and add them in. my js file:

const rpc = require("discord-rpc");
const client = new rpc.Client({
    transport: "ipc"
})

client.on('ready', () => {
    client.setActivity({
        details: 'Stuff',
        state: 'test',
        startTimestamp: new Date(),
        largeImageKey: image,
        largeImageText: `Working on ${cap(image)}`,
        smallImageKey: 'small',
        smallImageText: 'v0.1.0',
    })
})

const updateState = string => {
    client.setActivity({
        state: 'test2',
    })
}

module.exports = { updateState };
Lachee commented 2 years ago

The raw discord-rpc doesn't provide single field updates. Some libraries do provide it, but if its not available you will have to implement it yourself.

Just store the presence, make changes to that object, and then call setActivity on the entire object again:

let presence = {
  details: 'stuff',
};

function setState(state) {
  presence.state = state;
  client.setActivity(presence);
}

^^^ pseudo example

ghost commented 2 years ago

const rpc = require("discord-rpc");

wrong repository, you're looking for https://github.com/discordjs/RPC

(but yes, what Lachee said is correct)