if discord rpc cant find discord running how to make it refresh

301 Views Asked by At

Hi so my problem is that when i run my application which uses discord-rpc it connects to discord if it is already running. However if Discord is not running and the application is launched before Discord the rpc will not connect to discord automatically. How can i make this code sort of refresh say every 10 seconds

rpc = require("discord-rpc")
const client = new rpc.Client({ transport: 'ipc' })
client.on('ready', () => {
    client.request('SET_ACTIVITY', {
        pid: process.pid,
        

        
        activity : {
            details : "Loading Melody (Beta)",
            
           
            assets : {
                large_image : ""
                large_text : "This Is A Test"
            },
            
            buttons : [{label : "Download Melody" , url : "https://github.com/unofficialdxnny/Melody"}]
        
        
        }
        
    })
    

})

client.login({ clientId : "token" } ).catch(console.error);

1

There are 1 best solutions below

0
On

First of all, make a Boolean which is saved globally. Now if you can successfully login, set it to true. Now wrap the whole code in a set interval, and a if condition based on that boolean to check whether do you need to run the code again or not. You probably need to run the client login part in that set interval.