Skip to content

Commit 2fbb39a

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

14 files changed

+41
-15
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ 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);
7881

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ 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);
108111
if (resolvedUser) return this._fetchSingle({ user: resolvedUser, cache, force });

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ 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);
223226
if (resolvedUser && !limit && !withPresences) return this._fetchSingle({ user: resolvedUser, cache, force });

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ 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);
205208
if (resolvedSoundboardSound) return this._fetchSingle({ cache, force, soundboardSound: resolvedSoundboardSound });

0 commit comments

Comments
 (0)