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 toolkitβ€’2y 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/lunaOPβ€’2y ago
lemme get some screens
treble/luna
treble/lunaOPβ€’2y 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 Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/lunaOPβ€’2y ago
well even then i dont update the nickname so the nickname should not change
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/lunaOPβ€’2y 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 Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/lunaOPβ€’2y ago
tried on 14.11, same issue
souji
soujiβ€’2y 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/lunaOPβ€’2y ago
the user has a nickname set for the server, and i'm adding the role right after the bot restarts
souji
soujiβ€’2y ago
so the member is uncached?
treble/luna
treble/lunaOPβ€’2y ago
the member is uncached, but since the oldMember is a partial i fetch first
souji
soujiβ€’2y ago
ah, so you have the member partial
treble/luna
treble/lunaOPβ€’2y ago
yee
souji
soujiβ€’2y ago
kinda relevant
treble/luna
treble/lunaOPβ€’2y ago
sorry, should have mentioned
souji
soujiβ€’2y 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/lunaOPβ€’2y ago
yes, but i never update the nickname from the oldMember, but it still returns null while having one set
souji
soujiβ€’2y 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/lunaOPβ€’2y ago
ah, still weird that it returns null though. I did managed to bypass it by using the auditlog event instead
souji
soujiβ€’2y 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/lunaOPβ€’2y ago
yeah thats what i'm wondering. i've also noticed that 14.11 also does this
souji
soujiβ€’2y ago
-ev msg.guild.members.fetch("455777603706421249", {force: true}).then(m => m.nickname)
yuzu
yuzuβ€’2y ago
'luna🌈'
'luna🌈'
β€’ d.js 14.12.1 β€’ Type: string β€’ time taken: 0.272589ms
duck
duckβ€’2y 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
soujiβ€’2y 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
[πŸͺ] KNKβ€’2y ago
guys how is possible to see the colours in the code??
d.js docs
d.js docsβ€’2y 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
soujiβ€’2y 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
Want results from more Discord servers?
Add your server