Discord.js: guildMemberRemove not firing in some cases

Created on 28 Nov 2020  Â·  4Comments  Â·  Source: discordjs/discord.js

Hello,

Please note this is not an issue that can be fixed by enabling the server members gateway intent, I have already enabled this.

Since what appears to be a few weeks ago, the guildMemberRemove event seems to not fire in some cases. I believe it has something to do with caching. If a user joins the guild and then leaves without restarting the Discord.js application, the event is fired correctly. The issue only seems to occur if a user joins the guild, the Discord.js application is restarted after a user has joined, and the user then leaves - this does not trigger the event.

Reproduction steps:

  1. Start Discord.js application
  2. New user joins the guild
  3. Restart Discord.js application
  4. That user leaves the guild - event is not fired
client.on("guildMemberRemove", (guildmember) => {
        console.log("Member left: " + guildmember.id);
}

Further details:

  • discord.js version: 12.5.1
  • Node.js version: 12.8.1
  • Operating system: Windows 10
  • Priority this issue should have – please be realistic and elaborate if possible: medium

Relevant client options:

  • partials: none
  • gateway intents: Server members
  • other: none

  • [ ] I have also tested the issue on latest master, commit hash:

question (please use Discord instead)

All 4 comments

This is because the GuildMember is uncached - you will need the GUILD_MEMBER partial in order to listen for events for uncached GuildMembers.

https://discordjs.guide/popular-topics/partials.html?v=12
https://discord.js.org/#/docs/main/stable/topics/partials

The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.

Thanks for the quick reply @monbrey Having read the documentation on Partials, this is potentially an issue for me then. My bot is in two separate guilds and it is crucial that I know which guild the member has been removed from.

If the GuildMember is partial, I won't be able to reliably access guildmember.guild.id from what I understand. Furthermore, because the GuildMember has been removed from the guild, there is no opportunity for me to fetch() the GuildMember.

How should I reliably obtain the following data from a partial GuildMember that has been removed from the guild, or at least find out which guild the member has been removed from?

  • guildmember.guild.id
  • guildmember.user.tag (less important than the guild id but still preferable)

Please take questions to the Discord server.

For anyone that finds this, quick summary of the Discord conversation following on from this:

space 🌹 replied to Albo1125Today at 22:44
A partial guild member object includes both guild and user.
Albo1125 replied to space 🌹Today at 22:46
That's a lifesaver. Is there anything else we can assume that a partial guildmember reliably includes? Given that on the Partials docs page it states specifically that Partial data is only ever guaranteed to contain an ID
space 🌹Today at 22:47
I think that's it for guild members.
MonbreyToday at 22:47
Generally speaking you can check what Discord actually emits for the event, and go from there
https://discord.com/developers/docs/topics/gateway#guild-member-remove-guild-member-remove-event-fields
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
The fact that this does include a guild_id means you'll know which guild
Common issues people run into for example is a partial Message object in messageDelete does not include its content

TL;DR Partial GuildMembers include both the guild and the user.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xCuzImPro picture xCuzImPro  Â·  3Comments

PassTheMayo picture PassTheMayo  Â·  3Comments

DatMayo picture DatMayo  Â·  3Comments

Blumlaut picture Blumlaut  Â·  3Comments

Acaretia picture Acaretia  Â·  3Comments