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