Skip to content

Commit b63cdb3

Browse files
committed
refactor: consistent use of resolve instead of cache.get() ?? null
1 parent 2b0944a commit b63cdb3

9 files changed

+16
-16
lines changed

packages/discord.js/src/structures/AutoModerationActionExecution.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class AutoModerationActionExecution {
8282
* @readonly
8383
*/
8484
get autoModerationRule() {
85-
return this.guild.autoModerationRules.cache.get(this.ruleId) ?? null;
85+
return this.guild.autoModerationRules.resolve(this.ruleId);
8686
}
8787

8888
/**
@@ -91,7 +91,7 @@ class AutoModerationActionExecution {
9191
* @readonly
9292
*/
9393
get channel() {
94-
return this.guild.channels.cache.get(this.channelId) ?? null;
94+
return this.guild.channels.resolve(this.channelId);
9595
}
9696

9797
/**
@@ -100,7 +100,7 @@ class AutoModerationActionExecution {
100100
* @readonly
101101
*/
102102
get user() {
103-
return this.guild.client.users.cache.get(this.userId) ?? null;
103+
return this.guild.client.users.resolve(this.userId);
104104
}
105105

106106
/**
@@ -109,7 +109,7 @@ class AutoModerationActionExecution {
109109
* @readonly
110110
*/
111111
get member() {
112-
return this.guild.members.cache.get(this.userId) ?? null;
112+
return this.guild.members.resolve(this.userId);
113113
}
114114
}
115115

packages/discord.js/src/structures/AutocompleteInteraction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AutocompleteInteraction extends BaseInteraction {
6262
*/
6363
get command() {
6464
const id = this.commandId;
65-
return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null;
65+
return this.guild?.commands.cache.get(id) ?? this.client.application.commands.resolve(id);
6666
}
6767

6868
/**

packages/discord.js/src/structures/BaseInteraction.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class BaseInteraction extends Base {
147147
* @readonly
148148
*/
149149
get channel() {
150-
return this.client.channels.cache.get(this.channelId) ?? null;
150+
return this.client.channels.resolve(this.channelId);
151151
}
152152

153153
/**
@@ -156,7 +156,7 @@ class BaseInteraction extends Base {
156156
* @readonly
157157
*/
158158
get guild() {
159-
return this.client.guilds.cache.get(this.guildId) ?? null;
159+
return this.client.guilds.resolve(this.guildId);
160160
}
161161

162162
/**

packages/discord.js/src/structures/ClientApplication.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class ClientApplication extends Application {
260260
* @readonly
261261
*/
262262
get guild() {
263-
return this.client.guilds.cache.get(this.guildId) ?? null;
263+
return this.client.guilds.resolve(this.guildId);
264264
}
265265

266266
/**

packages/discord.js/src/structures/CommandInteraction.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CommandInteraction extends BaseInteraction {
7676
*/
7777
get command() {
7878
const id = this.commandId;
79-
return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null;
79+
return this.guild?.commands.cache.get(id) ?? this.client.application.commands.resolve(id);
8080
}
8181

8282
/**

packages/discord.js/src/structures/Entitlement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Entitlement extends Base {
107107
*/
108108
get guild() {
109109
if (!this.guildId) return null;
110-
return this.client.guilds.cache.get(this.guildId) ?? null;
110+
return this.client.guilds.resolve(this.guildId);
111111
}
112112

113113
/**

packages/discord.js/src/structures/GuildAuditLogsEntry.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class GuildAuditLogsEntry {
153153
this.executor = data.user_id
154154
? guild.client.options.partials.includes(Partials.User)
155155
? guild.client.users._add({ id: data.user_id })
156-
: (guild.client.users.cache.get(data.user_id) ?? null)
156+
: guild.client.users.resolve(data.user_id)
157157
: null;
158158

159159
/**
@@ -299,7 +299,7 @@ class GuildAuditLogsEntry {
299299
} else if (targetType === Targets.User && data.target_id) {
300300
this.target = guild.client.options.partials.includes(Partials.User)
301301
? guild.client.users._add({ id: data.target_id })
302-
: (guild.client.users.cache.get(data.target_id) ?? null);
302+
: guild.client.users.resolve(data.target_id);
303303
} else if (targetType === Targets.Guild) {
304304
this.target = guild.client.guilds.cache.get(data.target_id);
305305
} else if (targetType === Targets.Webhook) {
@@ -323,7 +323,7 @@ class GuildAuditLogsEntry {
323323
this.target =
324324
data.action_type === AuditLogEvent.MessageBulkDelete
325325
? (guild.channels.cache.get(data.target_id) ?? { id: data.target_id })
326-
: (guild.client.users.cache.get(data.target_id) ?? null);
326+
: guild.client.users.resolve(data.target_id);
327327
} else if (targetType === Targets.Integration) {
328328
this.target =
329329
logs?.integrations.get(data.target_id) ??

packages/discord.js/src/structures/VoiceChannelEffect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class VoiceChannelEffect {
6262
* @readonly
6363
*/
6464
get channel() {
65-
return this.guild.channels.cache.get(this.channelId) ?? null;
65+
return this.guild.channels.resolve(this.channelId);
6666
}
6767
}
6868

packages/discord.js/src/structures/VoiceState.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class VoiceState extends Base {
136136
* @readonly
137137
*/
138138
get member() {
139-
return this.guild.members.cache.get(this.id) ?? null;
139+
return this.guild.members.resolve(this.id);
140140
}
141141

142142
/**
@@ -145,7 +145,7 @@ class VoiceState extends Base {
145145
* @readonly
146146
*/
147147
get channel() {
148-
return this.guild.channels.cache.get(this.channelId) ?? null;
148+
return this.guild.channels.resolve(this.channelId);
149149
}
150150

151151
/**

0 commit comments

Comments
 (0)