Skip to content
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

fix(User): fix bot and system properties being incorrect in some cases #5923

Merged
merged 5 commits into from
Jun 27, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/structures/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class User extends Base {
*/
this.id = data.id;

this.bot = null;

this.system = null;

this.flags = null;

/**
Expand Down Expand Up @@ -56,12 +59,14 @@ class User extends Base {
this.username = null;
}

if ('bot' in data || typeof this.bot !== 'boolean') {
if ('bot' in data || typeof this.bot === 'boolean') {
/**
* Whether or not the user is a bot
* @type {boolean}
* @type {?boolean}
*/
this.bot = Boolean(data.bot);
this.bot = Boolean(data.bot ?? this.bot);
} else if (!this.partial) {
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
this.bot = false;
}

if ('discriminator' in data) {
Expand All @@ -84,12 +89,14 @@ class User extends Base {
this.avatar = null;
}

if ('system' in data) {
if ('system' in data || typeof this.system === 'boolean') {
/**
* Whether the user is an Official Discord System user (part of the urgent message system)
* @type {?boolean}
*/
this.system = Boolean(data.system);
this.system = Boolean(data.system ?? this.system);
} else if (!this.partial) {
this.system = false;
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
}

if ('public_flags' in data) {
Expand Down
6 changes: 3 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ declare module 'discord.js' {
public lastMessageID: Snowflake | null;
public readonly partial: false;
public readonly presence: Presence;
public system: boolean | null;
public system: boolean;
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
public readonly tag: string;
public username: string;
public avatarURL(options?: ImageURLOptions): string | null;
Expand Down Expand Up @@ -3777,9 +3777,9 @@ declare module 'discord.js' {
type PartialTypes = 'USER' | 'CHANNEL' | 'GUILD_MEMBER' | 'MESSAGE' | 'REACTION';

interface PartialUser extends Omit<Partialize<User, 'bot' | 'flags' | 'system' | 'tag' | 'username'>, 'deleted'> {
bot: User['bot'];
bot: null;
flags: User['flags'];
system: User['system'];
system: null;
readonly tag: null;
username: null;
}
Expand Down