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:
ckohen
2021-05-10 03:27:36 -07:00
committed by GitHub
parent 533c2471c2
commit 1ecda83da7
4 changed files with 27 additions and 8 deletions

View File

@@ -175,12 +175,15 @@ class APIMessage {
}
let message_reference;
if (typeof this.options.replyTo !== 'undefined') {
if (typeof this.options.reply === 'object') {
const message_id = this.isMessage
? this.target.channel.messages.resolveID(this.options.replyTo)
: this.target.messages.resolveID(this.options.replyTo);
? this.target.channel.messages.resolveID(this.options.reply.messageReference)
: this.target.messages.resolveID(this.options.reply.messageReference);
if (message_id) {
message_reference = { message_id };
message_reference = {
message_id,
fail_if_not_exists: this.options.reply.failIfNotExists ?? true,
};
}
}

View File

@@ -610,7 +610,7 @@ class Message extends Base {
* Send an inline reply to this message.
* @param {StringResolvable|APIMessage} [content=''] The content for the message
* @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[]>}
*/
reply(content, options) {
@@ -618,7 +618,10 @@ class Message extends Base {
content instanceof APIMessage
? content
: APIMessage.transformOptions(content, options, {
replyTo: this,
reply: {
messageReference: this,
failIfNotExists: options?.reply?.failIfNotExists ?? content?.reply?.failIfNotExists ?? true,
},
}),
);
}

View File

@@ -63,7 +63,7 @@ class TextBasedChannel {
* @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
* 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
*/
/**
* 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.
* @param {StringResolvable|APIMessage} [content=''] The content to send

7
typings/index.d.ts vendored
View File

@@ -3198,7 +3198,7 @@ declare module 'discord.js' {
files?: (FileOptions | BufferResolvable | Stream | MessageAttachment)[];
code?: string | boolean;
split?: boolean | SplitOptions;
replyTo?: MessageResolvable;
reply?: ReplyOptions;
}
type MessageReactionResolvable = MessageReaction | Snowflake;
@@ -3447,6 +3447,11 @@ declare module 'discord.js' {
maxUsers?: number;
}
interface ReplyOptions {
messageReference: MessageResolvable;
failIfNotExists?: boolean;
}
interface ResolvedOverwriteOptions {
allow: Permissions;
deny: Permissions;