-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix(GuildMember): cache without partial structures #10785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(GuildMember): cache without partial structures #10785
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
packages/discord.js/src/client/websocket/handlers/PRESENCE_UPDATE.js
Outdated
Show resolved
Hide resolved
| private constructor(guild: Guild, iterable?: Iterable<RawGuildMemberData>); | ||
| public guild: Guild; | ||
| public get me(): GuildMember | null; | ||
| public get me(): GuildMember | PartialGuildMember | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always get the full GuildMember data for the ClientUser on GUILD_CREATE, so this can never be a PartialGuildMember to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GUILD_CREATE not emit if Guilds intent not set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without Guilds intent you wouldn't have any GuildMembers cached and the whole GuildMemberManager would be inaccessible because you don't have a Guild having it as property to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What prevents us from using fetch to get and cache guilds with specific members exclude client member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discord.js/packages/discord.js/src/managers/GuildMemberManager.js
Lines 138 to 145 in a30a749
| get me() { | |
| return ( | |
| this.cache.get(this.client.user.id) ?? | |
| (this.client.options.partials.includes(Partials.GuildMember) | |
| ? this._add({ user: { id: this.client.user.id } }, true) | |
| : null) | |
| ); | |
| } |
And if it like you say, why exist this functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that's a good catch indeed. Guess GuildMemberManager#me can be a PartialGuildMember after all, if the GuildMemberManager cache is limited to 0 without exception for the ClientUser.
But about no Guilds intent: most of the typings rely on that being present. Because several helper methods need it to work anyway.
| | Guild | ||
| | NonThreadGuildBasedChannel | ||
| | GuildMember | ||
| | PartialGuildMember |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it makes much sense to resolve a Guild from a partial member, but that one's up to debate I'd say
| export interface PartialGuildMemberRoleManager extends Partialize<GuildMemberRoleManager, null, null, 'member'> { | ||
| get partial(): true; | ||
| member: PartialGuildMember; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand need I and how to override constructor
…azov/discord.js into fix-partial-guildMember-typing
|
That's about it. If I forgot something, please remind me. |
Please describe the changes this PR makes and why it should be merged:
This PR based on previous PR's conversation.
Discord API's Guild Member object has isn't nullable
joinedAtproperty.This also confirms the partial property set to false, which depends on the nullability of
joinedAtand the use ofPartializefor this property to create thePartialGuildMemberinterface.It's also incorrect that caching of a partial member is performed despite the provided partials options.
Status and versioning classification: