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
- 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!lemme get some screens
When adding a role, this is what
console.log(oldMember.nickname, newMember.nickname)
returns https://bork.treble-is-fluffy.gay/floofd140de03.png
Full code:
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 addedUnknown User•16mo ago
Message Not Public
Sign In & Join Server To View
well even then
i dont update the nickname
so the nickname should not change
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
i dont think my embed code would be the culprit but sending just in case
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
tried on 14.11, same issue
i attached that listener and i cannot reproduce the issue
how exactly are you reproducing it?
add a role to a member?
the user has a nickname set for the server, and i'm adding the role right after the bot restarts
so the member is uncached?
the member is uncached, but since the oldMember is a partial i fetch first
ah, so you have the member partial
yee
kinda relevant
sorry, should have mentioned
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?
yes, but i never update the nickname from the oldMember, but it still returns null while having one set
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 APIah, still weird that it returns null though. I did managed to bypass it by using the auditlog event instead
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 youyeah thats what i'm wondering. i've also noticed that 14.11 also does this
-ev msg.guild.members.fetch("455777603706421249", {force: true}).then(m => m.nickname)
• d.js
14.12.1
• Type: string
• time taken: 0.272589ms
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
how does that even interact with the cloning?
we clone old member to emit it, what if you call fetch on that one
guys how is possible to see the colours in the code??
Codeblocks:
```js
const Discord = require("discord.js");
// further code
```
becomes
Inline Code:
`console.log('inline!');` becomes
console.log('inline!');
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 thanks qjuh, duck