From 261612596d37aa6fb48ae070d358b3fde953c769 Mon Sep 17 00:00:00 2001 From: Jan <66554238+vaporox@users.noreply.github.com> Date: Fri, 25 Jun 2021 12:07:31 +0200 Subject: [PATCH] feat(MessageMentions): add repliedUser (#5905) --- src/structures/Message.js | 10 +++++++++- src/structures/MessageMentions.js | 8 +++++++- typings/index.d.ts | 5 ++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index ad85fec29..59ea77fdd 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -190,7 +190,14 @@ class Message extends Base { * All valid mentions that the message contains * @type {MessageMentions} */ - this.mentions = new Mentions(this, data.mentions, data.mention_roles, data.mention_everyone, data.mention_channels); + this.mentions = new Mentions( + this, + data.mentions, + data.mention_roles, + data.mention_everyone, + data.mention_channels, + data.referenced_message?.author, + ); /** * ID of the webhook that sent the message, if applicable @@ -325,6 +332,7 @@ class Message extends Base { 'mention_roles' in data ? data.mention_roles : this.mentions.roles, 'mention_everyone' in data ? data.mention_everyone : this.mentions.everyone, 'mention_channels' in data ? data.mention_channels : this.mentions.crosspostedChannels, + 'referenced_message' in data ? data.referenced_message.author : this.mentions.repliedUser, ); this.flags = new MessageFlags('flags' in data ? data.flags : 0).freeze(); diff --git a/src/structures/MessageMentions.js b/src/structures/MessageMentions.js index d4d5fd52a..af16eabb4 100644 --- a/src/structures/MessageMentions.js +++ b/src/structures/MessageMentions.js @@ -8,7 +8,7 @@ const Util = require('../util/Util'); * Keeps track of mentions in a {@link Message}. */ class MessageMentions { - constructor(message, users, roles, everyone, crosspostedChannels) { + constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) { /** * The client the message is from * @type {Client} @@ -125,6 +125,12 @@ class MessageMentions { } else { this.crosspostedChannels = new Collection(); } + + /** + * The author of the message that this message is a reply to + * @type {?User} + */ + this.repliedUser = repliedUser ? this.client.users.add(repliedUser) : null; } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 6b63fa2fd..970d70e44 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -147,6 +147,7 @@ declare module 'discord.js' { APIPartialEmoji as RawEmoji, APIRole as RawRole, Snowflake as APISnowflake, + APIUser, ApplicationCommandOptionType as ApplicationCommandOptionTypes, ApplicationCommandPermissionType as ApplicationCommandPermissionTypes, } from 'discord-api-types/v8'; @@ -1492,9 +1493,10 @@ declare module 'discord.js' { export class MessageMentions { constructor( message: Message, - users: unknown[] | Collection, + users: APIUser[] | Collection, roles: Snowflake[] | Collection, everyone: boolean, + repliedUser?: APIUser | User, ); private _channels: Collection | null; private readonly _content: string; @@ -1506,6 +1508,7 @@ declare module 'discord.js' { public readonly guild: Guild; public has(data: UserResolvable | RoleResolvable | ChannelResolvable, options?: MessageMentionsHasOptions): boolean; public readonly members: Collection | null; + public repliedUser: User | null; public roles: Collection; public users: Collection; public crosspostedChannels: Collection;