newPresence returns undefined inside presenceUpdate event

code
client.on('presenceUpdate', async (oldPresence, newPresence) => {
if (newPresence.member.presence.status.includes("something")) {
..

} else {
return console.log('this ' + newPresence)
}
});
client.on('presenceUpdate', async (oldPresence, newPresence) => {
if (newPresence.member.presence.status.includes("something")) {
..

} else {
return console.log('this ' + newPresence)
}
});
25 Replies
d.js toolkit
d.js toolkit15mo 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!
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
pup
pupOP15mo ago
yes
Mark
Mark15mo ago
why not just do newPresence.status...
pup
pupOP15mo ago
because im looking for the members custom status
Mark
Mark15mo ago
do you have an event handler
pup
pupOP15mo ago
no
Mark
Mark15mo ago
what's the actual error you receive or unexpected behavior you see because newPresence cannot be undefined and also have newPresence.member not error
pup
pupOP15mo ago
i'm not recieving an error im recieving undefined
Mark
Mark15mo ago
you still don't need to do newPresence.member.presence what is undefined
pup
pupOP15mo ago
returns undefined newPresence
Mark
Mark15mo ago
it can't, you'd receive an error with that code something like cannot read properties of undefined, reading member or some such
pup
pupOP15mo ago
...
this undefined
this undefined
console says otherwise
Mark
Mark15mo ago
show the full event code please
pup
pupOP15mo ago
client.on('presenceUpdate', async (oldPresence, newPresence) => {
if (newPresence.member.presence.status.includes("something")) {
let userProfile = await UserProfile.findOne({
userid: newPresence.member.id,
});

if (userProfile) {
const lastPresenceDate = userProfile.lastPresenceCollected?.toDateString();
const currenDate = new Date().toDateString();

if (lastPresenceDate === currenDate) {
console.log('WAITTT A DAY.').catch((err) => console.error(err));
return;
}
} else {
userProfile = new UserProfile({
userid: interaction.member.id,
});
}

userProfile.balance += presenceAmount;
userProfile.lastPresenceCollected = new Date();

await userProfile.save();

console.log(`You claimed **$${presenceAmount}** from daily reward!`)
} else {
return console.log('this ' + newPresence)
}
});
client.on('presenceUpdate', async (oldPresence, newPresence) => {
if (newPresence.member.presence.status.includes("something")) {
let userProfile = await UserProfile.findOne({
userid: newPresence.member.id,
});

if (userProfile) {
const lastPresenceDate = userProfile.lastPresenceCollected?.toDateString();
const currenDate = new Date().toDateString();

if (lastPresenceDate === currenDate) {
console.log('WAITTT A DAY.').catch((err) => console.error(err));
return;
}
} else {
userProfile = new UserProfile({
userid: interaction.member.id,
});
}

userProfile.balance += presenceAmount;
userProfile.lastPresenceCollected = new Date();

await userProfile.save();

console.log(`You claimed **$${presenceAmount}** from daily reward!`)
} else {
return console.log('this ' + newPresence)
}
});
the code inside is not done yet but that doesn't matter
Mark
Mark15mo ago
that log cannot return undefined, it would error at the first if statement
pup
pupOP15mo ago
...
Mark
Mark15mo ago
log oldPresence, newPresence on the first line of the listener
pup
pupOP15mo ago
undefined and undefined
undefined and undefined
ha
client.on('presenceUpdate', async (oldPresence, newPresence) => {
console.log(oldPresence + ' and ' + newPresence)
if (newPresence.member.presence.status.includes("something")) {
let userProfile = await UserProfile.findOne({
userid: newPresence.member.id,
});

if (userProfile) {
const lastPresenceDate = userProfile.lastPresenceCollected?.toDateString();
const currenDate = new Date().toDateString();

if (lastPresenceDate === currenDate) {
console.log('WAITTT A DAY.').catch((err) => console.error(err));
return;
}
} else {
userProfile = new UserProfile({
userid: interaction.member.id,
});
}

userProfile.balance += presenceAmount;
userProfile.lastPresenceCollected = new Date();

await userProfile.save();

console.log(`You claimed **$${presenceAmount}** from daily reward!`)
}
});
client.on('presenceUpdate', async (oldPresence, newPresence) => {
console.log(oldPresence + ' and ' + newPresence)
if (newPresence.member.presence.status.includes("something")) {
let userProfile = await UserProfile.findOne({
userid: newPresence.member.id,
});

if (userProfile) {
const lastPresenceDate = userProfile.lastPresenceCollected?.toDateString();
const currenDate = new Date().toDateString();

if (lastPresenceDate === currenDate) {
console.log('WAITTT A DAY.').catch((err) => console.error(err));
return;
}
} else {
userProfile = new UserProfile({
userid: interaction.member.id,
});
}

userProfile.balance += presenceAmount;
userProfile.lastPresenceCollected = new Date();

await userProfile.save();

console.log(`You claimed **$${presenceAmount}** from daily reward!`)
}
});
Mark
Mark15mo ago
are you using client.emit() to test this?
pup
pupOP15mo ago
hm? no
console.log('this ' + newPresence)
console.log('this ' + newPresence)
returns undefined oh you mean ah gotchu yeah it returns the presence so how do i get custom status of user than
d.js docs
d.js docs15mo ago
property Presence#activities The activities of this presence
pup
pupOP15mo ago
alr ty alr thanks activities is returning not a function might be using it wrong
Mark
Mark15mo ago
it's an array
pup
pupOP15mo ago
but how do i use te state property? i got it sry i was being stupid :(( didn't even realise i was replying sorry
Want results from more Discord servers?
Add your server