Weird issue with GuildMemberUpdate event

i'm running into a really weird issue with the guildMemberUpdate event when adding a role: For some reason the nickname is null on the oldMember, whilst having one set The newMember does have a nickname, and since i check for nicnkame updates by comparing <GuildMember>.displayName, the bot thinks the nickname has updated while it has not.
31 Replies
d.js toolkit
d.js toolkit10mo 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!
treble/luna
treble/luna10mo ago
lemme get some screens
treble/luna
treble/luna10mo ago
When adding a role, this is what console.log(oldMember.nickname, newMember.nickname) returns https://bork.treble-is-fluffy.gay/floofd140de03.png Full code:
async execute(oldMember: GuildMember, newMember: GuildMember){
if(oldMember.partial) await oldMember.fetch();
console.log(oldMember.nickname, newMember.nickname)

const c = newMember.client.channels.cache.get('980917365162258464');
if(!c?.isTextBased()) return
let eb = new EmbedBuilder().setColor('Aqua')

console.log(oldMember.displayName, newMember.displayName)

if(oldMember.displayName != newMember.displayName) {
//rest of the logging logic
async execute(oldMember: GuildMember, newMember: GuildMember){
if(oldMember.partial) await oldMember.fetch();
console.log(oldMember.nickname, newMember.nickname)

const c = newMember.client.channels.cache.get('980917365162258464');
if(!c?.isTextBased()) return
let eb = new EmbedBuilder().setColor('Aqua')

console.log(oldMember.displayName, newMember.displayName)

if(oldMember.displayName != newMember.displayName) {
//rest of the logging logic
Its also really unstable, it always happens after a restart (when oldMember is a partial and is fetched), but sometimes it also happens when i remove the role that i added
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna10mo ago
well even then i dont update the nickname so the nickname should not change
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna10mo ago
i dont think my embed code would be the culprit but sending just in case
eb.addFields({
name: "Old name",
value: oldMember.displayName
}, {
name: "New name",
value: newMember.displayName
})
c.send({embeds: [eb]})
}
eb.addFields({
name: "Old name",
value: oldMember.displayName
}, {
name: "New name",
value: newMember.displayName
})
c.send({embeds: [eb]})
}
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna10mo ago
tried on 14.11, same issue
souji
souji10mo ago
client.on("guildMemberUpdate", (om, nm) => om.displayName !== nm.displayName && channel.send(`om: ${om.displayName} nm: ${nm.displayName}`))
client.on("guildMemberUpdate", (om, nm) => om.displayName !== nm.displayName && channel.send(`om: ${om.displayName} nm: ${nm.displayName}`))
i attached that listener and i cannot reproduce the issue how exactly are you reproducing it? add a role to a member?
treble/luna
treble/luna10mo ago
the user has a nickname set for the server, and i'm adding the role right after the bot restarts
souji
souji10mo ago
so the member is uncached?
treble/luna
treble/luna10mo ago
the member is uncached, but since the oldMember is a partial i fetch first
souji
souji10mo ago
ah, so you have the member partial
treble/luna
treble/luna10mo ago
yee
souji
souji10mo ago
kinda relevant
treble/luna
treble/luna10mo ago
sorry, should have mentioned
souji
souji10mo ago
how do you even expect this to work? you are fetching the oldMember - which will fetch the newest state from the API and then compare it to the new member?
treble/luna
treble/luna10mo ago
yes, but i never update the nickname from the oldMember, but it still returns null while having one set
souji
souji10mo ago
i can somewhat reproduce it, in that i got [dev-application] | treble/luna >> luna🌈 when i added a role to you that's odd, but still, that approach cannot work you are fetching the member from the API AFTER you received an update in doing so you will lose the state from before the update, which we retrieve from the cahce and emit as old member in this event. if there was none, then there is none, fetching it won't change that, it will be the newest state from the API
treble/luna
treble/luna10mo ago
ah, still weird that it returns null though. I did managed to bypass it by using the auditlog event instead
souji
souji10mo ago
so you are comparing the newest api state to the updated (new) member now, why that display name change, i do not understand - yet the partial member has null as nick before the update, that makes sense after fetching the partial, it still has null as nickname, that makes no sense the member being you
treble/luna
treble/luna10mo ago
yeah thats what i'm wondering. i've also noticed that 14.11 also does this
souji
souji10mo ago
-ev msg.guild.members.fetch("455777603706421249", {force: true}).then(m => m.nickname)
yuzu
yuzu10mo ago
'luna🌈'
'luna🌈'
• d.js 14.12.1 • Type: string • time taken: 0.272589ms
duck
duck10mo ago
fetching patches the existing cached object, so at the point of fetching, the old member isn't the cached member so oldMember doesn't get updated
souji
souji10mo ago
how does that even interact with the cloning? we clone old member to emit it, what if you call fetch on that one
[🪐] KNK
[🪐] KNK10mo ago
guys how is possible to see the colours in the code??
d.js docs
d.js docs10mo ago
Codeblocks: ```js const Discord = require("discord.js"); // further code ``` becomes
const Discord = require("discord.js");
// further code
const Discord = require("discord.js");
// further code
Inline Code: `console.log('inline!');` becomes console.log('inline!');
souji
souji10mo ago
firT okay, so the old member is still partial, so the null nickname makes sense -ev console.log("+++++++++++++") -ev msg.guild.members.cache.clear() which also changes the displayName getter, makes sense solved Wiggle thanks qjuh, duck