[discord-rpc] Prevent multiple listeners

guys I have a question
app.post('/extension-call', (req, res) => {
if (req.body.playing === true) {

updateRpc(req.body.name, req.body.icon, 'Playing')
}
else {
updateRpc(null, null, 'Browsing')
}
});
app.post('/extension-call', (req, res) => {
if (req.body.playing === true) {

updateRpc(req.body.name, req.body.icon, 'Playing')
}
else {
updateRpc(null, null, 'Browsing')
}
});
and inside updateRpc I have client.login using client id, setactivity function and etc, how to do so it does not create multiple listeners except only one?
function updatePresence() {
return client.setActivity({
details: rpc.details,
state: rpc.state,
largeImageKey: rpc.assets.largeImageKey,
largeImageText: rpc.assets.largeImageText,
smallImageKey: rpc.assets.smallImageKey,
smallImageText: rpc.assets.smallImageText,
buttons:
[{
label: rpc.buttons.primary.buttonLabelText,
url: rpc.buttons.primary.buttonRedirectUrl
},
{
label: rpc.buttons.secondary.buttonLabelText,
url: rpc.buttons.secondary.buttonRedirectUrl
}
],
startTimestamp: new Date()


}, process.pid)
}
client.on('ready', async () => {
onStartup();
});
if(/* here */) client.login({ clientId: config.clientId }).catch();
}
function updatePresence() {
return client.setActivity({
details: rpc.details,
state: rpc.state,
largeImageKey: rpc.assets.largeImageKey,
largeImageText: rpc.assets.largeImageText,
smallImageKey: rpc.assets.smallImageKey,
smallImageText: rpc.assets.smallImageText,
buttons:
[{
label: rpc.buttons.primary.buttonLabelText,
url: rpc.buttons.primary.buttonRedirectUrl
},
{
label: rpc.buttons.secondary.buttonLabelText,
url: rpc.buttons.secondary.buttonRedirectUrl
}
],
startTimestamp: new Date()


}, process.pid)
}
client.on('ready', async () => {
onStartup();
});
if(/* here */) client.login({ clientId: config.clientId }).catch();
}
3 Replies
d.js toolkit
d.js toolkit16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
VLADY 🛡
VLADY 🛡OP16mo ago
I tried
client.on('ready', async () => {
onStartup();
});
if(client.listenerCount('ready') < 1) client.login({ clientId: config.clientId }).catch(); // Prevents multiple listeners
console.log(client.listenerCount('ready'))
client.on('ready', async () => {
onStartup();
});
if(client.listenerCount('ready') < 1) client.login({ clientId: config.clientId }).catch(); // Prevents multiple listeners
console.log(client.listenerCount('ready'))
still getting Browsing 1 Playing 2 Browsing 3 multiple listeners
Seren_Modz 21
Seren_Modz 2116mo ago
Want results from more Discord servers?
Add your server