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
d.js toolkit
d.js toolkit11mo 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!
InFiNiTy
InFiNiTy11mo ago
force fetch oldMember Or just fetch To check if it actually throw GuildMember object or just undefined
Kinect3000
Kinect300011mo ago
You can’t fetch old data Better off relying on the audit log event instead for tracking this sort of change
d.js docs
d.js docs11mo ago
event (event) Client#guildAuditLogEntryCreate Emitted whenever a guild audit log entry is created.
InFiNiTy
InFiNiTy11mo ago
Honestly I havent coded anything in djs since long ago, could forgot some things 😐
Kinect3000
Kinect300011mo ago
It’s a fairly new event They have it enabled. The issue is that they don’t have the old data of the member
oxi
oxiOP10mo ago
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
Kinect3000
Kinect300010mo ago
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
oxi
oxiOP10mo ago
guildAuditLogEntryCreate seems to run twice for each event, am I doing something wrong?
oxi
oxiOP10mo ago
export default event('guildAuditLogEntryCreate', async ({ client }, auditLogEntry, guild) => {
const { action } = auditLogEntry;
if(action !== AuditLogEvent.MemberRoleUpdate) return;

console.log(guild.name, auditLogEntry.changes);
// . . .
export default event('guildAuditLogEntryCreate', async ({ client }, auditLogEntry, guild) => {
const { action } = auditLogEntry;
if(action !== AuditLogEvent.MemberRoleUpdate) return;

console.log(guild.name, auditLogEntry.changes);
// . . .
No description
oxi
oxiOP10mo ago
actually nevermind. its an issue with how im loading it
oxi
oxiOP10mo ago
No description
Want results from more Discord servers?
Add your server