presence update

Wondering how to differentiate when a person starts a new activtity, such as listening to spotify and that the activity should not be exisiting in old presence. For exaple, user is playing a game + spotify, if spotify updates , the game remains same, it should not show game.
if (!oldPresence) return;
if (newPresence.activities.length === 0) return;

const { guild, userId, activities } = newPresence;

console.log(newPresence);

let str = "";

for (const activity of activities) {
const { type, state, details, name } = activity;

if (type === ActivityType.Custom) continue;
if (type === 6) continue; // vc channel activity

const isSameActivity = oldPresence.activities.some((oldActivity) =>
activity.equals(oldActivity)
);

if (isSameActivity) continue;
}
if (!str) return;
if (!oldPresence) return;
if (newPresence.activities.length === 0) return;

const { guild, userId, activities } = newPresence;

console.log(newPresence);

let str = "";

for (const activity of activities) {
const { type, state, details, name } = activity;

if (type === ActivityType.Custom) continue;
if (type === 6) continue; // vc channel activity

const isSameActivity = oldPresence.activities.some((oldActivity) =>
activity.equals(oldActivity)
);

if (isSameActivity) continue;
}
if (!str) return;
here's what i got so far, seems to work. The .equals how does it work? it seems like if i am running vs code since few hours (timestamp property of activity showing start as few hours ago) but edit a new file (createdTimestamp updates), it says true. Is there anyway for me to modify it so it only show when the presence actually starts (running vs code)
1 Reply
d.js toolkit
d.js toolkit•4mo 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!
Want results from more Discord servers?
Add your server