diff --git a/src/managers/ThreadManager.js b/src/managers/ThreadManager.js index 429761fd5..315a00bac 100644 --- a/src/managers/ThreadManager.js +++ b/src/managers/ThreadManager.js @@ -71,16 +71,12 @@ class ThreadManager extends CachedManager { /** * Options for creating a thread. Only one of `startMessage` or `type` can be defined. - * @typedef {Object} ThreadCreateOptions - * @property {string} name The name of the new thread - * @property {ThreadAutoArchiveDuration} autoArchiveDuration The amount of time (in minutes) after which the thread - * should automatically archive in case of no recent activity + * @typedef {StartThreadOptions} ThreadCreateOptions * @property {MessageResolvable} [startMessage] The message to start a thread from. If this is defined then type * of thread gets automatically defined and cannot be changed. The provided `type` field will be ignored * @property {ThreadChannelTypes|number} [type] The type of thread to create. Defaults to `GUILD_PUBLIC_THREAD` if * created in a {@link TextChannel} When creating threads in a {@link NewsChannel} this is ignored and is always * `GUILD_NEWS_THREAD` - * @property {string} [reason] Reason for creating the thread */ /** diff --git a/src/structures/Message.js b/src/structures/Message.js index f462eb239..536b628de 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -727,20 +727,27 @@ class Message extends Base { return this.channel.send(data); } + /** + * Options for starting a thread on a message. + * @typedef {Object} StartThreadOptions + * @property {string} name The name of the new thread + * @property {ThreadAutoArchiveDuration} autoArchiveDuration The amount of time (in minutes) after which the thread + * should automatically archive in case of no recent activity + * @property {string} [reason] Reason for creating the thread + */ + /** * Create a new public thread from this message * @see ThreadManager#create - * @param {string} name The name of the new Thread - * @param {ThreadAutoArchiveDuration} autoArchiveDuration How long before the thread is automatically archived - * @param {string} [reason] Reason for creating the thread + * @param {StartThreadOptions} [options] Options for starting a thread on this message * @returns {Promise} */ - startThread(name, autoArchiveDuration, reason) { + startThread(options = {}) { if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(this.channel.type)) { return Promise.reject(new Error('MESSAGE_THREAD_PARENT')); } if (this.hasThread) return Promise.reject(new Error('MESSAGE_EXISTING_THREAD')); - return this.channel.threads.create({ name, autoArchiveDuration, startMessage: this, reason }); + return this.channel.threads.create({ ...options, startMessage: this }); } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 04e8a8f52..b4ceecc16 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1031,11 +1031,7 @@ export class Message extends Base { public react(emoji: EmojiIdentifierResolvable): Promise; public removeAttachments(): Promise; public reply(options: string | MessagePayload | ReplyMessageOptions): Promise; - public startThread( - name: string, - autoArchiveDuration: ThreadAutoArchiveDuration, - reason?: string, - ): Promise; + public startThread(options: StartThreadOptions): Promise; public suppressEmbeds(suppress?: boolean): Promise; public toJSON(): unknown; public toString(): string; @@ -4278,6 +4274,12 @@ export interface StaticImageURLOptions { export type StageInstanceResolvable = StageInstance | Snowflake; +export interface StartThreadOptions { + name: string; + autoArchiveDuration: ThreadAutoArchiveDuration; + reason?: string; +} + export type Status = number; export type StickerFormatType = keyof typeof StickerFormatTypes; @@ -4325,12 +4327,9 @@ export type ThreadChannelResolvable = ThreadChannel | Snowflake; export type ThreadChannelTypes = 'GUILD_NEWS_THREAD' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD'; -export interface ThreadCreateOptions { - name: string; - autoArchiveDuration: ThreadAutoArchiveDuration; +export interface ThreadCreateOptions extends StartThreadOptions { startMessage?: MessageResolvable; type?: AllowedThreadType; - reason?: string; } export interface ThreadEditData {