Merge pull request #161 from SpeedyCraftah/main
refactor(TheardManager): Add user account functionality for fetching active threads
This commit is contained in:
commit
72238015f9
@ -225,16 +225,30 @@ class ThreadManager extends CachedManager {
|
|||||||
return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache });
|
return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discord.js self-bot specific options field for fetching active threads.
|
||||||
|
* @typedef {Object} FetchChannelThreadsOptions
|
||||||
|
* @property {string} [sort_by] The order in which the threads should be fetched in (default is last_message_time)
|
||||||
|
* @property {string} [sort_order] How the threads should be ordered (default is desc)
|
||||||
|
* @property {number} [limit] The maximum number of threads to return (default is 25)
|
||||||
|
* @property {number} [offset] The number of threads to offset fetching (useful when making multiple fetches) (default is 0)
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains the accessible active threads from Discord, requires `READ_MESSAGE_HISTORY` in the parent channel.
|
* Obtains the accessible active threads from Discord, requires `READ_MESSAGE_HISTORY` in the parent channel.
|
||||||
* @param {boolean} [cache=true] Whether to cache the new thread objects if they aren't already
|
* @param {boolean} [cache=true] Whether to cache the new thread objects if they aren't already
|
||||||
|
* @param {FetchChannelThreadsOptions} [selfbot_options] Options for self-bots where advanced users can specify further options
|
||||||
* @returns {Promise<FetchedThreads>}
|
* @returns {Promise<FetchedThreads>}
|
||||||
*/
|
*/
|
||||||
async fetchActive(cache = true) {
|
async fetchActive(cache = true, options = null) {
|
||||||
if (!this.client.user.bot) {
|
if (options && this.client.user.bot) {
|
||||||
throw new Error('INVALID_USER_METHOD: User accounts cannot use this method\nI will fix it .-.');
|
throw new Error('INVALID_BOT_OPTIONS: Options can only be specified for user accounts.');
|
||||||
}
|
}
|
||||||
const raw = await this.client.api.guilds(this.channel.guild.id).threads.active.get();
|
|
||||||
|
const raw = this.client.user.bot ?
|
||||||
|
await this.client.api.guilds(this.channel.guild.id).threads.active.get()
|
||||||
|
: await this.client.api.channels(this.channel.id).threads[`search?archived=false&limit=${options?.limit || '25'}&offset=${options?.offset || '0'}&sort_by=${options?.sort_by || 'last_message_time'}&sort_order=${options?.sort_order || 'desc'}`].get();
|
||||||
|
|
||||||
return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache });
|
return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user