guildMemberUpdate, function not executing as expected
Node.js: v20.5.1
Discord.js: v14.13.0
https://hastebin.com/share/etonilifab.typescript
This function executes completely fine on the second, third and fourth execution. However, on the first it is unable to get oldMember, as it is not cached.
How would I be able to have it so that it allows for me to synchronise their roles correctly? I attempted to use partials yet this did not work as roles can be added yet not removed.
Hastebin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
12 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!force fetch oldMember
Or just fetch
To check if it actually throw GuildMember object or just undefined
You can’t fetch old data
Better off relying on the audit log event instead for tracking this sort of change
Honestly I havent coded anything in djs since long ago, could forgot some things 😐
It’s a fairly new event
They have it enabled. The issue is that they don’t have the old data of the member
Sorry just seen this now, I was thinking about using partials
are audit logs more reliable than partials would be in this case?
just wondering what the best approach would be is, using this to cross-sync roles accross two guilds and dont want them to get out of sync because of a caching issue
ah yeah sorry just seen that it was the audit logs event, that will be as reliable as guildMemberUpdate, i was thinking it was fetching the logs via api and then getting the data that way.
will attempt to implement it now
Yes.
Partials just allow you to receive the event, even if some of the data is missing. In this case, the old member data may not be present
guildAuditLogEntryCreate seems to run twice for each event, am I doing something wrong?
actually nevermind. its an issue with how im loading it