Skip to content

Commit 53aa24d

Browse files
fix(ThreadManager): Ensure fetchActive() only returns active threads in a channel (#9568)
fix(ThreadManager): revert breaking change Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 9b06734 commit 53aa24d

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,17 @@ class GuildChannelManager extends CachedManager {
468468
* .catch(console.error);
469469
*/
470470
async fetchActiveThreads(cache = true) {
471-
const raw = await this.client.rest.get(Routes.guildActiveThreads(this.guild.id));
472-
return GuildTextThreadManager._mapThreads(raw, this.client, { guild: this.guild, cache });
471+
const data = await this.rawFetchGuildActiveThreads();
472+
return GuildTextThreadManager._mapThreads(data, this.client, { guild: this.guild, cache });
473+
}
474+
475+
/**
476+
* `GET /guilds/{guild.id}/threads/active`
477+
* @private
478+
* @returns {Promise<RESTGetAPIGuildThreadsResult>}
479+
*/
480+
rawFetchGuildActiveThreads() {
481+
return this.client.rest.get(Routes.guildActiveThreads(this.guild.id));
473482
}
474483

475484
/**

packages/discord.js/src/managers/ThreadManager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ class ThreadManager extends CachedManager {
171171
}
172172

173173
/**
174-
* Obtains all active thread channels in the guild.
175-
* This internally calls {@link GuildChannelManager#fetchActiveThreads}.
174+
* Obtains all active threads in the channel.
176175
* @param {boolean} [cache=true] Whether to cache the fetched data
177176
* @returns {Promise<FetchedThreads>}
178177
*/
179-
fetchActive(cache = true) {
180-
return this.channel.guild.channels.fetchActiveThreads(cache);
178+
async fetchActive(cache = true) {
179+
const data = await this.channel.guild.channels.rawFetchGuildActiveThreads();
180+
return this.constructor._mapThreads(data, this.client, { parent: this.channel, cache });
181181
}
182182

183183
static _mapThreads(rawThreads, client, { parent, guild, cache }) {

packages/discord.js/src/util/APITypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@
400400
* @see {@link https://discord-api-types.dev/api/discord-api-types-payloads/common#PermissionFlagsBits}
401401
*/
402402

403+
/**
404+
* @external RESTGetAPIGuildThreadsResult
405+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#RESTGetAPIGuildThreadsResult}
406+
*/
407+
403408
/**
404409
* @external RESTJSONErrorCodes
405410
* @see {@link https://discord-api-types.dev/api/discord-api-types-rest/common/enum/RESTJSONErrorCodes}

packages/discord.js/typings/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ import {
156156
APIApplicationRoleConnectionMetadata,
157157
ImageFormat,
158158
GuildMemberFlags,
159+
RESTGetAPIGuildThreadsResult,
159160
} from 'discord-api-types/v10';
160161
import { ChildProcess } from 'node:child_process';
161162
import { EventEmitter } from 'node:events';
@@ -3860,6 +3861,7 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
38603861
): Promise<GuildChannel>;
38613862
public setPositions(channelPositions: readonly ChannelPosition[]): Promise<Guild>;
38623863
public fetchActiveThreads(cache?: boolean): Promise<FetchedThreads>;
3864+
private rawFetchGuildActiveThreads(): Promise<RESTGetAPIGuildThreadsResult>;
38633865
public delete(channel: GuildChannelResolvable, reason?: string): Promise<void>;
38643866
}
38653867

0 commit comments

Comments
 (0)