refactor: use cache.get() for snowflakes, resolve() otherwise
#10626 djs
This commit is contained in:
@@ -259,7 +259,7 @@ class GuildMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get presence() {
|
||||
return this.guild.presences.resolve(this.id);
|
||||
return this.guild.presences.cache.get(this.id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ class Invite extends Base {
|
||||
*/
|
||||
this.guild ??= null;
|
||||
if (data.guild) {
|
||||
this.guild = this.client.guilds.resolve(data.guild.id) ?? new InviteGuild(this.client, data.guild);
|
||||
this.guild = this.client.guilds.cache.get(data.guild.id) ?? new InviteGuild(this.client, data.guild);
|
||||
}
|
||||
|
||||
if ('code' in data) {
|
||||
|
||||
@@ -273,7 +273,7 @@ class Message extends Base {
|
||||
* @type {Collection<Snowflake, Message>}
|
||||
*/
|
||||
this.messageSnapshots = data.message_snapshots.reduce((coll, snapshot) => {
|
||||
const channel = this.client.channels.resolve(this.reference.channelId);
|
||||
const channel = this.client.channels.cache.get(this.reference.channelId);
|
||||
const snapshotData = {
|
||||
...snapshot.message,
|
||||
id: this.reference.messageId,
|
||||
@@ -464,7 +464,7 @@ class Message extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get channel() {
|
||||
return this.client.channels.resolve(this.channelId);
|
||||
return this.client.channels.cache.get(this.channelId) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -510,7 +510,7 @@ class Message extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get guild() {
|
||||
return this.client.guilds.resolve(this.guildId) ?? this.channel?.guild ?? null;
|
||||
return this.client.guilds.cache.get(this.guildId) ?? this.channel?.guild ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -530,7 +530,7 @@ class Message extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get thread() {
|
||||
return this.channel?.threads?.resolve(this.id) ?? null;
|
||||
return this.channel?.threads?.cache.get(this.id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -180,7 +180,7 @@ class PermissionOverwrites extends Base {
|
||||
};
|
||||
}
|
||||
|
||||
const userOrRole = guild.roles.resolve(overwrite.id) ?? guild.client.users.resolve(overwrite.id);
|
||||
const userOrRole = guild.roles.cache.get(overwrite.id) ?? guild.client.users.cache.get(overwrite.id);
|
||||
if (!userOrRole) throw new TypeError('INVALID_TYPE', 'parameter', 'User nor a Role');
|
||||
const type = userOrRole instanceof Role ? OverwriteTypes.role : OverwriteTypes.member;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class PollAnswer extends Base {
|
||||
*/
|
||||
get emoji() {
|
||||
if (!this._emoji || (!this._emoji.id && !this._emoji.name)) return null;
|
||||
return this.client.emojis.resolve(this._emoji.id) ?? new Emoji(this.client, this._emoji);
|
||||
return this.client.emojis.cache.get(this._emoji.id) ?? new Emoji(this.client, this._emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,7 +61,7 @@ class ThreadMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get guildMember() {
|
||||
return this.member ?? this.thread.guild.members.resolve(this.id);
|
||||
return this.member ?? this.thread.guild.members.cache.get(this.id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +79,7 @@ class ThreadMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get user() {
|
||||
return this.client.users.resolve(this.id);
|
||||
return this.client.users.cache.get(this.id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -93,7 +93,7 @@ class Webhook {
|
||||
* The source guild of the webhook
|
||||
* @type {?(Guild|APIGuild)}
|
||||
*/
|
||||
this.sourceGuild = this.client.guilds?.resolve(data.source_guild.id) ?? data.source_guild;
|
||||
this.sourceGuild = this.client.guilds?.cache.get(data.source_guild.id) ?? data.source_guild;
|
||||
} else {
|
||||
this.sourceGuild ??= null;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class Webhook {
|
||||
* The source channel of the webhook
|
||||
* @type {?(NewsChannel|APIChannel)}
|
||||
*/
|
||||
this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel;
|
||||
this.sourceChannel = this.client.channels?.cache.get(data.source_channel?.id) ?? data.source_channel;
|
||||
} else {
|
||||
this.sourceChannel ??= null;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class WelcomeChannel extends Base {
|
||||
* @type {?(TextChannel|NewsChannel|StoreChannel|ForumChannel|MediaChannel)}
|
||||
*/
|
||||
get channel() {
|
||||
return this.client.channels.resolve(this.channelId);
|
||||
return this.client.channels.cache.get(this.channelId) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ class WelcomeChannel extends Base {
|
||||
* @type {GuildEmoji|Emoji}
|
||||
*/
|
||||
get emoji() {
|
||||
return this.client.emojis.resolve(this._emoji.id) ?? new Emoji(this.client, this._emoji);
|
||||
return this.client.emojis.cache.get(this._emoji.id) ?? new Emoji(this.client, this._emoji);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user