guildMemberUpdate doesn't fire for users that joined when the bot was offline

Hello, I'm trying to make a bot that will give a role to an user that has accepted the server rules by checking for the pending property, what I found peculiar is that if the user joined when the bot is offline, when the bot comes back online it refuses to give that user a role even when that user accept the rules. And I also found out that calling await client.guilds.cache.get(guildID).members.fetch() on ready event resolves that issue. Any heads up? Here is my code and a video demonstrating the issue. I have already enabled Guilds and GuildMembers intents, and this issue doesn't occur when the user joins when the bot is up. Or more specifically, it doesn't even fire guildMemberUpdate, as to why the console.log() didn't fire. I don't want to call a fetch for guild members because my bot's prod guild has over 4k members.
19 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Azure
Azure2y ago
Extra Information: Node Version: 16.17.0 Discord.js version: 14.4.0 What is partials?
d.js docs
d.js docs2y ago
guide Popular Topics: Partial Structures read more
Azure
Azure2y ago
So I have to enable some partials for it to register offline users when coming back online?
조아오
조아오2y ago
Isn't this the guildMemberAdd event??
Azure
Azure2y ago
It is in guildMemberUpdate.
조아오
조아오2y ago
I know, I'm talking about the member passing membership screening
Azure
Azure2y ago
with some logging oldMember is partial, I have to call .fetch()?
조아오
조아오2y ago
I think it emits a guildMemberAdd Not a guildMemberUpdate New member should be a full member You can't fetch the old member
Azure
Azure2y ago
The guildMemberAdd event didn't fire when the user accepts the rules, I had a console.log() in it
조아오
조아오2y ago
Yeah, my bad them
Azure
Azure2y ago
Is this viable to put in prod?
조아오
조아오2y ago
What you want to do? Checking if the member is pending and add role if changes the state?
Azure
Azure2y ago
Yes
조아오
조아오2y ago
If it's working Thats fine Try this: (oldMember.pending !== newMember.pending) || (!newMember.pending && !newMember.roles.cache.has(roleId))
Azure
Azure2y ago
let me try it out
조아오
조아오2y ago
Should work for all tree cases if I'm not dumb
Azure
Azure2y ago
It works Thanks you guys for the support ❤️
조아오
조아오2y ago
Makes sense, my bad on that