Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Message): add ReplyMessageOptions for #reply #5296

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,27 @@ class Message extends Base {
return this;
}

/**
* Options provided when sending a message as an inline reply.
* @typedef {Object} ReplyMessageOptions
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud
* @property {string} [nonce=''] The nonce for the message
* @property {string} [content=''] The content for the message
* @property {MessageEmbed|Object} [embed] An embed for the message
* (see [here](https://discord.com/developers/docs/resources/channel#embed-object) for more details)
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
* @property {FileOptions[]|BufferResolvable[]} [files] Files to send with the message
* @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 {boolean} [failIfNotExists=true] Whether to error if the referenced message
* does not exist (creates a standard message in this case when false)
*/

/**
* 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.reply.messageReference=this] The message to reply to
* @param {ReplyMessageOptions|MessageAdditions} [options] The additional options to provide
* @returns {Promise<Message|Message[]>}
*/
reply(content, options) {
Expand All @@ -620,7 +636,7 @@ class Message extends Base {
: APIMessage.transformOptions(content, options, {
reply: {
messageReference: this,
failIfNotExists: options?.reply?.failIfNotExists ?? content?.reply?.failIfNotExists ?? true,
failIfNotExists: options?.failIfNotExists ?? content?.failIfNotExists ?? true,
},
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/structures/interfaces/TextBasedChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TextBasedChannel {
* @property {MessageMentionTypes[]} [parse] Types of mentions to be parsed
* @property {Snowflake[]} [users] Snowflakes of Users to be parsed as mentions
* @property {Snowflake[]} [roles] Snowflakes of Roles to be parsed as mentions
* @property {boolean} [repliedUser] Whether the author of the Message being replied to should be pinged
* @property {boolean} [repliedUser=true] Whether the author of the Message being replied to should be pinged
*/

/**
Expand Down
16 changes: 10 additions & 6 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,19 +1148,19 @@ declare module 'discord.js' {
public react(emoji: EmojiIdentifierResolvable): Promise<MessageReaction>;
public removeAttachments(): Promise<Message>;
public reply(
content: APIMessageContentResolvable | (MessageOptions & { split?: false }) | MessageAdditions,
content: APIMessageContentResolvable | (ReplyMessageOptions & { split?: false }) | MessageAdditions,
): Promise<Message>;
public reply(options: MessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
public reply(options: MessageOptions | APIMessage): Promise<Message | Message[]>;
public reply(options: ReplyMessageOptions & { split: true | SplitOptions }): Promise<Message[]>;
public reply(options: ReplyMessageOptions | APIMessage): Promise<Message | Message[]>;
public reply(
content: StringResolvable,
options: (MessageOptions & { split?: false }) | MessageAdditions,
options: (ReplyMessageOptions & { split?: false }) | MessageAdditions,
): Promise<Message>;
public reply(
content: StringResolvable,
options: MessageOptions & { split: true | SplitOptions },
options: ReplyMessageOptions & { split: true | SplitOptions },
): Promise<Message[]>;
public reply(content: StringResolvable, options: MessageOptions): Promise<Message | Message[]>;
public reply(content: StringResolvable, options: ReplyMessageOptions): Promise<Message | Message[]>;
public suppressEmbeds(suppress?: boolean): Promise<Message>;
public toJSON(): object;
public toString(): string;
Expand Down Expand Up @@ -3481,6 +3481,10 @@ declare module 'discord.js' {
failIfNotExists?: boolean;
}

interface ReplyMessageOptions extends Omit<MessageOptions, 'reply'> {
failIfNotExists?: boolean;
}

interface ResolvedOverwriteOptions {
allow: Permissions;
deny: Permissions;
Expand Down