mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
refactor(Message): accept a single object instead of 3 arguments (#6244)
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
@@ -71,16 +71,12 @@ class ThreadManager extends CachedManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for creating a thread. <warn>Only one of `startMessage` or `type` can be defined.</warn>
|
* Options for creating a thread. <warn>Only one of `startMessage` or `type` can be defined.</warn>
|
||||||
* @typedef {Object} ThreadCreateOptions
|
* @typedef {StartThreadOptions} 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
|
|
||||||
* @property {MessageResolvable} [startMessage] The message to start a thread from. <warn>If this is defined then type
|
* @property {MessageResolvable} [startMessage] The message to start a thread from. <warn>If this is defined then type
|
||||||
* of thread gets automatically defined and cannot be changed. The provided `type` field will be ignored</warn>
|
* of thread gets automatically defined and cannot be changed. The provided `type` field will be ignored</warn>
|
||||||
* @property {ThreadChannelTypes|number} [type] The type of thread to create. Defaults to `GUILD_PUBLIC_THREAD` if
|
* @property {ThreadChannelTypes|number} [type] The type of thread to create. Defaults to `GUILD_PUBLIC_THREAD` if
|
||||||
* created in a {@link TextChannel} <warn>When creating threads in a {@link NewsChannel} this is ignored and is always
|
* created in a {@link TextChannel} <warn>When creating threads in a {@link NewsChannel} this is ignored and is always
|
||||||
* `GUILD_NEWS_THREAD`</warn>
|
* `GUILD_NEWS_THREAD`</warn>
|
||||||
* @property {string} [reason] Reason for creating the thread
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -727,20 +727,27 @@ class Message extends Base {
|
|||||||
return this.channel.send(data);
|
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
|
* Create a new public thread from this message
|
||||||
* @see ThreadManager#create
|
* @see ThreadManager#create
|
||||||
* @param {string} name The name of the new Thread
|
* @param {StartThreadOptions} [options] Options for starting a thread on this message
|
||||||
* @param {ThreadAutoArchiveDuration} autoArchiveDuration How long before the thread is automatically archived
|
|
||||||
* @param {string} [reason] Reason for creating the thread
|
|
||||||
* @returns {Promise<ThreadChannel>}
|
* @returns {Promise<ThreadChannel>}
|
||||||
*/
|
*/
|
||||||
startThread(name, autoArchiveDuration, reason) {
|
startThread(options = {}) {
|
||||||
if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(this.channel.type)) {
|
if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(this.channel.type)) {
|
||||||
return Promise.reject(new Error('MESSAGE_THREAD_PARENT'));
|
return Promise.reject(new Error('MESSAGE_THREAD_PARENT'));
|
||||||
}
|
}
|
||||||
if (this.hasThread) return Promise.reject(new Error('MESSAGE_EXISTING_THREAD'));
|
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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
17
typings/index.d.ts
vendored
17
typings/index.d.ts
vendored
@@ -1031,11 +1031,7 @@ export class Message extends Base {
|
|||||||
public react(emoji: EmojiIdentifierResolvable): Promise<MessageReaction>;
|
public react(emoji: EmojiIdentifierResolvable): Promise<MessageReaction>;
|
||||||
public removeAttachments(): Promise<Message>;
|
public removeAttachments(): Promise<Message>;
|
||||||
public reply(options: string | MessagePayload | ReplyMessageOptions): Promise<Message>;
|
public reply(options: string | MessagePayload | ReplyMessageOptions): Promise<Message>;
|
||||||
public startThread(
|
public startThread(options: StartThreadOptions): Promise<ThreadChannel>;
|
||||||
name: string,
|
|
||||||
autoArchiveDuration: ThreadAutoArchiveDuration,
|
|
||||||
reason?: string,
|
|
||||||
): Promise<ThreadChannel>;
|
|
||||||
public suppressEmbeds(suppress?: boolean): Promise<Message>;
|
public suppressEmbeds(suppress?: boolean): Promise<Message>;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
public toString(): string;
|
public toString(): string;
|
||||||
@@ -4278,6 +4274,12 @@ export interface StaticImageURLOptions {
|
|||||||
|
|
||||||
export type StageInstanceResolvable = StageInstance | Snowflake;
|
export type StageInstanceResolvable = StageInstance | Snowflake;
|
||||||
|
|
||||||
|
export interface StartThreadOptions {
|
||||||
|
name: string;
|
||||||
|
autoArchiveDuration: ThreadAutoArchiveDuration;
|
||||||
|
reason?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type Status = number;
|
export type Status = number;
|
||||||
|
|
||||||
export type StickerFormatType = keyof typeof StickerFormatTypes;
|
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 type ThreadChannelTypes = 'GUILD_NEWS_THREAD' | 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD';
|
||||||
|
|
||||||
export interface ThreadCreateOptions<AllowedThreadType> {
|
export interface ThreadCreateOptions<AllowedThreadType> extends StartThreadOptions {
|
||||||
name: string;
|
|
||||||
autoArchiveDuration: ThreadAutoArchiveDuration;
|
|
||||||
startMessage?: MessageResolvable;
|
startMessage?: MessageResolvable;
|
||||||
type?: AllowedThreadType;
|
type?: AllowedThreadType;
|
||||||
reason?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ThreadEditData {
|
export interface ThreadEditData {
|
||||||
|
|||||||
Reference in New Issue
Block a user