mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
refactor(MessageOptions): move replyTo to reply#messageReference and add failIfNotExists (#5298)
Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: Shubham Parihar <shubhamparihar391@gmail.com>
This commit is contained in:
@@ -175,12 +175,15 @@ class APIMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let message_reference;
|
let message_reference;
|
||||||
if (typeof this.options.replyTo !== 'undefined') {
|
if (typeof this.options.reply === 'object') {
|
||||||
const message_id = this.isMessage
|
const message_id = this.isMessage
|
||||||
? this.target.channel.messages.resolveID(this.options.replyTo)
|
? this.target.channel.messages.resolveID(this.options.reply.messageReference)
|
||||||
: this.target.messages.resolveID(this.options.replyTo);
|
: this.target.messages.resolveID(this.options.reply.messageReference);
|
||||||
if (message_id) {
|
if (message_id) {
|
||||||
message_reference = { message_id };
|
message_reference = {
|
||||||
|
message_id,
|
||||||
|
fail_if_not_exists: this.options.reply.failIfNotExists ?? true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -610,7 +610,7 @@ class Message extends Base {
|
|||||||
* Send an inline reply to this message.
|
* Send an inline reply to this message.
|
||||||
* @param {StringResolvable|APIMessage} [content=''] The content for the message
|
* @param {StringResolvable|APIMessage} [content=''] The content for the message
|
||||||
* @param {MessageOptions|MessageAdditions} [options] The additional options to provide
|
* @param {MessageOptions|MessageAdditions} [options] The additional options to provide
|
||||||
* @param {MessageResolvable} [options.replyTo=this] The message to reply to
|
* @param {MessageResolvable} [options.reply.messageReference=this] The message to reply to
|
||||||
* @returns {Promise<Message|Message[]>}
|
* @returns {Promise<Message|Message[]>}
|
||||||
*/
|
*/
|
||||||
reply(content, options) {
|
reply(content, options) {
|
||||||
@@ -618,7 +618,10 @@ class Message extends Base {
|
|||||||
content instanceof APIMessage
|
content instanceof APIMessage
|
||||||
? content
|
? content
|
||||||
: APIMessage.transformOptions(content, options, {
|
: APIMessage.transformOptions(content, options, {
|
||||||
replyTo: this,
|
reply: {
|
||||||
|
messageReference: this,
|
||||||
|
failIfNotExists: options?.reply?.failIfNotExists ?? content?.reply?.failIfNotExists ?? true,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class TextBasedChannel {
|
|||||||
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
|
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
|
||||||
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
|
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
|
||||||
* it exceeds the character limit. If an object is provided, these are the options for splitting the message
|
* it exceeds the character limit. If an object is provided, these are the options for splitting the message
|
||||||
* @property {MessageResolvable} [replyTo] The message to reply to (must be in the same channel and not system)
|
* @property {ReplyOptions} [reply] The options for replying to a message
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,6 +98,14 @@ class TextBasedChannel {
|
|||||||
* @property {string} [append=''] Text to append to every piece except the last
|
* @property {string} [append=''] Text to append to every piece except the last
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for sending a message with a reply.
|
||||||
|
* @typedef {Object} ReplyOptions
|
||||||
|
* @param {MessageResolvable} messageReference The message to reply to (must be in the same channel and not system)
|
||||||
|
* @param {boolean} [failIfNotExists=true] Whether to error if the referenced message
|
||||||
|
* does not exist (creates a standard message in this case when false)
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to this channel.
|
* Sends a message to this channel.
|
||||||
* @param {StringResolvable|APIMessage} [content=''] The content to send
|
* @param {StringResolvable|APIMessage} [content=''] The content to send
|
||||||
|
|||||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -3198,7 +3198,7 @@ declare module 'discord.js' {
|
|||||||
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
|
||||||
code?: string | boolean;
|
code?: string | boolean;
|
||||||
split?: boolean | SplitOptions;
|
split?: boolean | SplitOptions;
|
||||||
replyTo?: MessageResolvable;
|
reply?: ReplyOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageReactionResolvable = MessageReaction | Snowflake;
|
type MessageReactionResolvable = MessageReaction | Snowflake;
|
||||||
@@ -3447,6 +3447,11 @@ declare module 'discord.js' {
|
|||||||
maxUsers?: number;
|
maxUsers?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ReplyOptions {
|
||||||
|
messageReference: MessageResolvable;
|
||||||
|
failIfNotExists?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
interface ResolvedOverwriteOptions {
|
interface ResolvedOverwriteOptions {
|
||||||
allow: Permissions;
|
allow: Permissions;
|
||||||
deny: Permissions;
|
deny: Permissions;
|
||||||
|
|||||||
Reference in New Issue
Block a user