-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix(GuildMember): cache based on partials options #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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ class GuildMemberManager extends CachedManager { | |
|
||
/** | ||
* The cache of this Manager | ||
* @type {Collection<Snowflake, GuildMember>} | ||
* @type {Collection<Snowflake, GuildMember | PartialGuildMember>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The whole idea of fixing this was that there won‘t be |
||
* @name GuildMemberManager#cache | ||
*/ | ||
|
||
|
@@ -42,7 +42,7 @@ class GuildMemberManager extends CachedManager { | |
/** | ||
* Resolves a {@link UserResolvable} to a {@link GuildMember} object. | ||
* @param {UserResolvable} member The user that is part of the guild | ||
* @returns {?GuildMember} | ||
* @returns {?(GuildMember | PartialGuildMember)} | ||
*/ | ||
resolve(member) { | ||
const memberResolvable = super.resolve(member); | ||
|
@@ -132,7 +132,7 @@ class GuildMemberManager extends CachedManager { | |
|
||
/** | ||
* The client user as a GuildMember of this guild | ||
* @type {?GuildMember} | ||
* @type {?(GuildMember | PartialGuildMember)} | ||
* @readonly | ||
*/ | ||
get me() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ class Presence extends Base { | |
|
||
/** | ||
* The member of this presence | ||
* @type {?GuildMember} | ||
* @type {?(GuildMember | PartialGuildMember)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
* @readonly | ||
*/ | ||
get member() { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -677,7 +677,7 @@ export class BaseGuildVoiceChannel extends GuildChannel { | |||||||||||||||||
public bitrate: number; | ||||||||||||||||||
public get full(): boolean; | ||||||||||||||||||
public get joinable(): boolean; | ||||||||||||||||||
public get members(): Collection<Snowflake, GuildMember>; | ||||||||||||||||||
public get members(): Collection<Snowflake, GuildMember | PartialGuildMember>; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public nsfw: boolean; | ||||||||||||||||||
public rateLimitPerUser: number | null; | ||||||||||||||||||
public rtcRegion: string | null; | ||||||||||||||||||
|
@@ -1541,7 +1541,10 @@ export class GuildBan extends Base { | |||||||||||||||||
|
||||||||||||||||||
export abstract class GuildChannel extends BaseChannel { | ||||||||||||||||||
public constructor(guild: Guild, data?: RawGuildChannelData, client?: Client<true>, immediatePatch?: boolean); | ||||||||||||||||||
private memberPermissions(member: GuildMember, checkAdmin: boolean): Readonly<PermissionsBitField>; | ||||||||||||||||||
private memberPermissions( | ||||||||||||||||||
member: GuildMember | PartialGuildMember, | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
checkAdmin: boolean, | ||||||||||||||||||
): Readonly<PermissionsBitField>; | ||||||||||||||||||
private rolePermissions(role: Role, checkAdmin: boolean): Readonly<PermissionsBitField>; | ||||||||||||||||||
public get createdAt(): Date; | ||||||||||||||||||
public get createdTimestamp(): number; | ||||||||||||||||||
|
@@ -1550,7 +1553,7 @@ export abstract class GuildChannel extends BaseChannel { | |||||||||||||||||
public guild: Guild; | ||||||||||||||||||
public guildId: Snowflake; | ||||||||||||||||||
public get manageable(): boolean; | ||||||||||||||||||
public get members(): Collection<Snowflake, GuildMember>; | ||||||||||||||||||
public get members(): Collection<Snowflake, GuildMember | PartialGuildMember>; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public name: string; | ||||||||||||||||||
public get parent(): CategoryChannel | null; | ||||||||||||||||||
public parentId: Snowflake | null; | ||||||||||||||||||
|
@@ -1565,7 +1568,10 @@ export abstract class GuildChannel extends BaseChannel { | |||||||||||||||||
public edit(options: GuildChannelEditOptions): Promise<this>; | ||||||||||||||||||
public equals(channel: GuildChannel): boolean; | ||||||||||||||||||
public lockPermissions(): Promise<this>; | ||||||||||||||||||
public permissionsFor(memberOrRole: GuildMember | Role, checkAdmin?: boolean): Readonly<PermissionsBitField>; | ||||||||||||||||||
public permissionsFor( | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
memberOrRole: GuildMember | PartialGuildMember | Role, | ||||||||||||||||||
checkAdmin?: boolean, | ||||||||||||||||||
): Readonly<PermissionsBitField>; | ||||||||||||||||||
public permissionsFor( | ||||||||||||||||||
memberOrRole: UserResolvable | RoleResolvable, | ||||||||||||||||||
checkAdmin?: boolean, | ||||||||||||||||||
|
@@ -1618,8 +1624,8 @@ export class GuildMember extends Base { | |||||||||||||||||
public get communicationDisabledUntil(): Date | null; | ||||||||||||||||||
public communicationDisabledUntilTimestamp: number | null; | ||||||||||||||||||
public flags: Readonly<GuildMemberFlagsBitField>; | ||||||||||||||||||
public get joinedAt(): Date | null; | ||||||||||||||||||
public joinedTimestamp: number | null; | ||||||||||||||||||
public get joinedAt(): Date; | ||||||||||||||||||
public joinedTimestamp: number; | ||||||||||||||||||
public get kickable(): boolean; | ||||||||||||||||||
public get manageable(): boolean; | ||||||||||||||||||
public get moderatable(): boolean; | ||||||||||||||||||
|
@@ -2135,7 +2141,7 @@ export class Message<InGuild extends boolean = boolean> extends Base { | |||||||||||||||||
public get hasThread(): boolean; | ||||||||||||||||||
public id: Snowflake; | ||||||||||||||||||
public interactionMetadata: MessageInteractionMetadata | null; | ||||||||||||||||||
public get member(): GuildMember | null; | ||||||||||||||||||
public get member(): GuildMember | PartialGuildMember | null; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public mentions: MessageMentions<InGuild>; | ||||||||||||||||||
public nonce: string | number | null; | ||||||||||||||||||
public get partial(): false; | ||||||||||||||||||
|
@@ -2370,15 +2376,15 @@ export class MessageMentions<InGuild extends boolean = boolean> { | |||||||||||||||||
); | ||||||||||||||||||
private _channels: Collection<Snowflake, Channel> | null; | ||||||||||||||||||
private readonly _content: string; | ||||||||||||||||||
private _members: Collection<Snowflake, GuildMember> | null; | ||||||||||||||||||
private _members: Collection<Snowflake, GuildMember | PartialGuildMember> | null; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
private _parsedUsers: Collection<Snowflake, User> | null; | ||||||||||||||||||
|
||||||||||||||||||
public get channels(): Collection<Snowflake, Channel>; | ||||||||||||||||||
public readonly client: Client; | ||||||||||||||||||
public everyone: boolean; | ||||||||||||||||||
public readonly guild: If<InGuild, Guild>; | ||||||||||||||||||
public has(data: UserResolvable | RoleResolvable | ChannelResolvable, options?: MessageMentionsHasOptions): boolean; | ||||||||||||||||||
public get members(): If<InGuild, Collection<Snowflake, GuildMember>>; | ||||||||||||||||||
public get members(): If<InGuild, Collection<Snowflake, GuildMember | PartialGuildMember>>; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public get parsedUsers(): Collection<Snowflake, User>; | ||||||||||||||||||
public repliedUser: User | null; | ||||||||||||||||||
public roles: Collection<Snowflake, Role>; | ||||||||||||||||||
|
@@ -2693,7 +2699,7 @@ export class Presence extends Base { | |||||||||||||||||
public activities: Activity[]; | ||||||||||||||||||
public clientStatus: ClientPresenceStatusData | null; | ||||||||||||||||||
public guild: Guild | null; | ||||||||||||||||||
public get member(): GuildMember | null; | ||||||||||||||||||
public get member(): GuildMember | PartialGuildMember | null; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be turned into an actual property, not a getter. |
||||||||||||||||||
public status: PresenceStatus; | ||||||||||||||||||
public get user(): User | null; | ||||||||||||||||||
public userId: Snowflake; | ||||||||||||||||||
|
@@ -2803,7 +2809,7 @@ export class Role extends Base { | |||||||||||||||||
public hoist: boolean; | ||||||||||||||||||
public id: Snowflake; | ||||||||||||||||||
public managed: boolean; | ||||||||||||||||||
public get members(): Collection<Snowflake, GuildMember>; | ||||||||||||||||||
public get members(): Collection<Snowflake, GuildMember | PartialGuildMember>; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public mentionable: boolean; | ||||||||||||||||||
public name: string; | ||||||||||||||||||
public permissions: Readonly<PermissionsBitField>; | ||||||||||||||||||
|
@@ -3355,7 +3361,10 @@ export class ThreadChannel<ThreadOnly extends boolean = boolean> extends BaseCha | |||||||||||||||||
public edit(options: ThreadEditOptions): Promise<this>; | ||||||||||||||||||
public join(): Promise<this>; | ||||||||||||||||||
public leave(): Promise<this>; | ||||||||||||||||||
public permissionsFor(memberOrRole: GuildMember | Role, checkAdmin?: boolean): Readonly<PermissionsBitField>; | ||||||||||||||||||
public permissionsFor( | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
memberOrRole: GuildMember | PartialGuildMember | Role, | ||||||||||||||||||
checkAdmin?: boolean, | ||||||||||||||||||
): Readonly<PermissionsBitField>; | ||||||||||||||||||
public permissionsFor( | ||||||||||||||||||
memberOrRole: UserResolvable | RoleResolvable, | ||||||||||||||||||
checkAdmin?: boolean, | ||||||||||||||||||
|
@@ -3403,7 +3412,7 @@ export class Typing extends Base { | |||||||||||||||||
public startedTimestamp: number; | ||||||||||||||||||
public get startedAt(): Date; | ||||||||||||||||||
public get guild(): Guild | null; | ||||||||||||||||||
public get member(): GuildMember | null; | ||||||||||||||||||
public get member(): GuildMember | PartialGuildMember | null; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public inGuild(): this is this & { | ||||||||||||||||||
channel: TextChannel | AnnouncementChannel | ThreadChannel; | ||||||||||||||||||
get guild(): Guild; | ||||||||||||||||||
|
@@ -3586,7 +3595,7 @@ export class VoiceState extends Base { | |||||||||||||||||
public get deaf(): boolean | null; | ||||||||||||||||||
public guild: Guild; | ||||||||||||||||||
public id: Snowflake; | ||||||||||||||||||
public get member(): GuildMember | null; | ||||||||||||||||||
public get member(): GuildMember | PartialGuildMember | null; | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public get mute(): boolean | null; | ||||||||||||||||||
public selfDeaf: boolean | null; | ||||||||||||||||||
public selfMute: boolean | null; | ||||||||||||||||||
|
@@ -4224,10 +4233,10 @@ export interface AddOrRemoveGuildMemberRoleOptions { | |||||||||||||||||
reason?: string; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, UserResolvable> { | ||||||||||||||||||
export class GuildMemberManager extends CachedManager<Snowflake, GuildMember | PartialGuildMember, UserResolvable> { | ||||||||||||||||||
Pavel-Boyazov marked this conversation as resolved.
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 commentThe reason will be displayed to describe this comment to others. Learn more. We always get the full There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What prevents us from using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
And if it like you say, why exist this functionality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, that's a good catch indeed. Guess |
||||||||||||||||||
public add( | ||||||||||||||||||
user: UserResolvable, | ||||||||||||||||||
options: AddGuildMemberOptions & { fetchWhenExisting: false }, | ||||||||||||||||||
|
@@ -4314,14 +4323,14 @@ export class GuildStickerManager extends CachedManager<Snowflake, Sticker, Stick | |||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
export class GuildMemberRoleManager extends DataManager<Snowflake, Role, RoleResolvable> { | ||||||||||||||||||
private constructor(member: GuildMember); | ||||||||||||||||||
private constructor(member: GuildMember | PartialGuildMember); | ||||||||||||||||||
public get hoist(): Role | null; | ||||||||||||||||||
public get icon(): Role | null; | ||||||||||||||||||
public get color(): Role | null; | ||||||||||||||||||
public get highest(): Role; | ||||||||||||||||||
public get premiumSubscriberRole(): Role | null; | ||||||||||||||||||
public get botRole(): Role | null; | ||||||||||||||||||
public member: GuildMember; | ||||||||||||||||||
public member: GuildMember | PartialGuildMember; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While technically correct this degrades UX. Probably better to add a |
||||||||||||||||||
public guild: Guild; | ||||||||||||||||||
|
||||||||||||||||||
public add( | ||||||||||||||||||
|
@@ -5959,7 +5968,15 @@ export interface GuildMemberEditOptions { | |||||||||||||||||
reason?: string; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
export type GuildResolvable = Guild | NonThreadGuildBasedChannel | GuildMember | GuildEmoji | Invite | Role | Snowflake; | ||||||||||||||||||
export type GuildResolvable = | ||||||||||||||||||
| Guild | ||||||||||||||||||
| NonThreadGuildBasedChannel | ||||||||||||||||||
| GuildMember | ||||||||||||||||||
| PartialGuildMember | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||||||||
| GuildEmoji | ||||||||||||||||||
| Invite | ||||||||||||||||||
| Role | ||||||||||||||||||
| Snowflake; | ||||||||||||||||||
|
||||||||||||||||||
export interface GuildPruneMembersOptions { | ||||||||||||||||||
count?: boolean; | ||||||||||||||||||
|
@@ -6864,7 +6881,7 @@ export type ThreadMemberResolvable = ThreadMember | UserResolvable; | |||||||||||||||||
|
||||||||||||||||||
export type UserMention = `<@${Snowflake}>`; | ||||||||||||||||||
|
||||||||||||||||||
export type UserResolvable = User | Snowflake | Message | GuildMember | ThreadMember; | ||||||||||||||||||
export type UserResolvable = User | Snowflake | Message | GuildMember | PartialGuildMember | ThreadMember; | ||||||||||||||||||
|
||||||||||||||||||
export interface Vanity { | ||||||||||||||||||
code: string | 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.
This needs more/better logic. The member should always be patched with that data, if cached before, but should never be newly added to cache. The
guildMemberAvaliable
event here should only emit if the partial is set. So add the partial check to the if conditions surrounding this block instead.Uh oh!
There was an error while loading. Please reload this page.
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 think it also needs to be emit if member object cached before. Didn't?
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.
No, if it's cache before then the
!member
condition would befalse
anyway.