Skip to content

Commit 847f9d3

Browse files
committed
fix: typing mismatch for empty strings being treated as undefined
1 parent 456a6f4 commit 847f9d3

14 files changed

+61
-22
lines changed

packages/discord.js/src/managers/ApplicationCommandManager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ class ApplicationCommandManager extends CachedManager {
123123
* .catch(console.error)
124124
*/
125125
async fetch(options) {
126-
if (!options) return this._fetchMany();
126+
if (options === undefined) {
127+
return this._fetchMany();
128+
}
127129

128130
if (typeof options === 'string') return this._fetchSingle({ id: options });
129131

packages/discord.js/src/managers/ApplicationEmojiManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ApplicationEmojiManager extends CachedManager {
8080
* .catch(console.error);
8181
*/
8282
async fetch(id, { cache = true, force = false } = {}) {
83-
if (id) {
83+
if (id !== undefined) {
8484
if (!force) {
8585
const existing = this.cache.get(id);
8686
if (existing) return existing;

packages/discord.js/src/managers/AutoModerationRuleManager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ class AutoModerationRuleManager extends CachedManager {
265265
* .catch(console.error)
266266
*/
267267
async fetch(options) {
268-
if (!options) return this._fetchMany();
268+
if (options === undefined) {
269+
return this._fetchMany();
270+
}
271+
269272
const { autoModerationRule, cache, force } = options;
270273
const resolvedAutoModerationRule = this.resolveId(autoModerationRule ?? options);
271274
if (resolvedAutoModerationRule) {

packages/discord.js/src/managers/EntitlementManager.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ class EntitlementManager extends CachedManager {
7272
* @returns {Promise<Entitlement|Collection<Snowflake, Entitlement>>}
7373
*/
7474
async fetch(options) {
75-
if (!options) return this._fetchMany(options);
75+
if (options === undefined) {
76+
return this._fetchMany(options);
77+
}
78+
7679
const { entitlement, cache, force } = options;
7780
const resolvedEntitlement = this.resolveId(entitlement ?? options);
78-
79-
if (resolvedEntitlement) {
81+
if (resolvedEntitlement !== null) {
8082
return this._fetchSingle({ entitlement: resolvedEntitlement, cache, force });
8183
}
8284

packages/discord.js/src/managers/GuildBanManager.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ class GuildBanManager extends CachedManager {
102102
* .catch(console.error);
103103
*/
104104
async fetch(options) {
105-
if (!options) return this._fetchMany();
105+
if (options === undefined) {
106+
return this._fetchMany();
107+
}
108+
106109
const { user, cache, force, limit, before, after } = options;
107110
const resolvedUser = this.client.users.resolveId(user ?? options);
108-
if (resolvedUser) return this._fetchSingle({ user: resolvedUser, cache, force });
111+
if (resolvedUser !== null) {
112+
return this._fetchSingle({ user: resolvedUser, cache, force });
113+
}
109114

110115
if (!before && !after && !limit && cache === undefined) {
111116
throw new DiscordjsError(ErrorCodes.FetchBanResolveId);

packages/discord.js/src/managers/GuildChannelManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,12 @@ class GuildChannelManager extends CachedManager {
418418
* .catch(console.error);
419419
*/
420420
async fetch(id, { cache = true, force = false } = {}) {
421-
if (id && !force) {
421+
if (id !== undefined && !force) {
422422
const existing = this.cache.get(id);
423423
if (existing) return existing;
424424
}
425425

426-
if (id) {
426+
if (id !== undefined) {
427427
const innerData = await this.client.rest.get(Routes.channel(id));
428428
// Since this is the guild manager, throw if on a different guild
429429
if (this.guild.id !== innerData.guild_id) throw new DiscordjsError(ErrorCodes.GuildChannelUnowned);

packages/discord.js/src/managers/GuildEmojiManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class GuildEmojiManager extends CachedManager {
179179
* .catch(console.error);
180180
*/
181181
async fetch(id, { cache = true, force = false } = {}) {
182-
if (id) {
182+
if (id !== undefined) {
183183
if (!force) {
184184
const existing = this.cache.get(id);
185185
if (existing) return existing;

packages/discord.js/src/managers/GuildInviteManager.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ class GuildInviteManager extends CachedManager {
142142
* .catch(console.error);
143143
*/
144144
async fetch(options) {
145-
if (!options) return this._fetchMany();
145+
if (options === undefined) {
146+
return this._fetchMany();
147+
}
148+
146149
if (typeof options === 'string') {
147150
const code = resolveInviteCode(options);
148151
if (!code) throw new DiscordjsError(ErrorCodes.InviteResolveCode);

packages/discord.js/src/managers/GuildMemberManager.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,16 @@ class GuildMemberManager extends CachedManager {
217217
* .catch(console.error);
218218
*/
219219
async fetch(options) {
220-
if (!options) return this._fetchMany();
220+
if (options === undefined) {
221+
return this._fetchMany();
222+
}
223+
221224
const { user: users, limit, withPresences, cache, force } = options;
222225
const resolvedUser = this.client.users.resolveId(users ?? options);
223-
if (resolvedUser && !limit && !withPresences) return this._fetchSingle({ user: resolvedUser, cache, force });
226+
if (resolvedUser !== null && !limit && !withPresences) {
227+
return this._fetchSingle({ user: resolvedUser, cache, force });
228+
}
229+
224230
const resolvedUsers = users?.map?.(user => this.client.users.resolveId(user)) ?? resolvedUser ?? undefined;
225231
return this._fetchMany({ ...options, users: resolvedUsers });
226232
}

packages/discord.js/src/managers/GuildSoundboardSoundManager.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,16 @@ class GuildSoundboardSoundManager extends CachedManager {
199199
* .catch(console.error);
200200
*/
201201
async fetch(options) {
202-
if (!options) return this._fetchMany();
202+
if (options === undefined) {
203+
return this._fetchMany();
204+
}
205+
203206
const { cache, force, soundboardSound } = options;
204207
const resolvedSoundboardSound = this.resolveId(soundboardSound ?? options);
205-
if (resolvedSoundboardSound) return this._fetchSingle({ cache, force, soundboardSound: resolvedSoundboardSound });
208+
if (resolvedSoundboardSound !== null) {
209+
return this._fetchSingle({ cache, force, soundboardSound: resolvedSoundboardSound });
210+
}
211+
206212
return this._fetchMany({ cache });
207213
}
208214

0 commit comments

Comments
 (0)