unofficialdxnny
unofficialdxnny

Reputation: 311

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

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);

Upvotes: 0

Views: 355

Answers (1)

Ren Hiyama
Ren Hiyama

Reputation: 479

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.

Upvotes: 0

Related Questions