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 toolkit17mo 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 User17mo ago
Message Not Public
Sign In & Join Server To View
pup
pupOP17mo ago
yes
Mark
Mark17mo ago
why not just do newPresence.status...
pup
pupOP17mo ago
because im looking for the members custom status
Mark
Mark17mo ago
do you have an event handler
pup
pupOP17mo ago
no
Mark
Mark17mo 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
pupOP17mo ago
i'm not recieving an error im recieving undefined
Mark
Mark17mo ago
you still don't need to do newPresence.member.presence what is undefined
pup
pupOP17mo ago
returns undefined newPresence
Mark
Mark17mo 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
pupOP17mo ago
...
this undefined
this undefined
console says otherwise
Mark
Mark17mo ago
show the full event code please
pup
pupOP17mo 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
Mark17mo ago
that log cannot return undefined, it would error at the first if statement
pup
pupOP17mo ago
...
Mark
Mark17mo ago
log oldPresence, newPresence on the first line of the listener
pup
pupOP17mo 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
Mark17mo ago
are you using client.emit() to test this?
pup
pupOP17mo 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 docs17mo ago
property Presence#activities The activities of this presence
pup
pupOP17mo ago
alr ty alr thanks activities is returning not a function might be using it wrong
Mark
Mark17mo ago
it's an array
pup
pupOP17mo 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