feat(MessageMentions): add repliedUser (#5905)

This commit is contained in:
Jan
2021-06-25 12:07:31 +02:00
committed by GitHub
parent 5af2ef5fbc
commit 261612596d
3 changed files with 20 additions and 3 deletions

View File

@@ -190,7 +190,14 @@ class Message extends Base {
* All valid mentions that the message contains * All valid mentions that the message contains
* @type {MessageMentions} * @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 * 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_roles' in data ? data.mention_roles : this.mentions.roles,
'mention_everyone' in data ? data.mention_everyone : this.mentions.everyone, 'mention_everyone' in data ? data.mention_everyone : this.mentions.everyone,
'mention_channels' in data ? data.mention_channels : this.mentions.crosspostedChannels, '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(); this.flags = new MessageFlags('flags' in data ? data.flags : 0).freeze();

View File

@@ -8,7 +8,7 @@ const Util = require('../util/Util');
* Keeps track of mentions in a {@link Message}. * Keeps track of mentions in a {@link Message}.
*/ */
class MessageMentions { class MessageMentions {
constructor(message, users, roles, everyone, crosspostedChannels) { constructor(message, users, roles, everyone, crosspostedChannels, repliedUser) {
/** /**
* The client the message is from * The client the message is from
* @type {Client} * @type {Client}
@@ -125,6 +125,12 @@ class MessageMentions {
} else { } else {
this.crosspostedChannels = new Collection(); 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;
} }
/** /**

5
typings/index.d.ts vendored
View File

@@ -147,6 +147,7 @@ declare module 'discord.js' {
APIPartialEmoji as RawEmoji, APIPartialEmoji as RawEmoji,
APIRole as RawRole, APIRole as RawRole,
Snowflake as APISnowflake, Snowflake as APISnowflake,
APIUser,
ApplicationCommandOptionType as ApplicationCommandOptionTypes, ApplicationCommandOptionType as ApplicationCommandOptionTypes,
ApplicationCommandPermissionType as ApplicationCommandPermissionTypes, ApplicationCommandPermissionType as ApplicationCommandPermissionTypes,
} from 'discord-api-types/v8'; } from 'discord-api-types/v8';
@@ -1492,9 +1493,10 @@ declare module 'discord.js' {
export class MessageMentions { export class MessageMentions {
constructor( constructor(
message: Message, message: Message,
users: unknown[] | Collection<Snowflake, User>, users: APIUser[] | Collection<Snowflake, User>,
roles: Snowflake[] | Collection<Snowflake, Role>, roles: Snowflake[] | Collection<Snowflake, Role>,
everyone: boolean, everyone: boolean,
repliedUser?: APIUser | User,
); );
private _channels: Collection<Snowflake, Channel> | null; private _channels: Collection<Snowflake, Channel> | null;
private readonly _content: string; private readonly _content: string;
@@ -1506,6 +1508,7 @@ declare module 'discord.js' {
public readonly guild: Guild; public readonly guild: Guild;
public has(data: UserResolvable | RoleResolvable | ChannelResolvable, options?: MessageMentionsHasOptions): boolean; public has(data: UserResolvable | RoleResolvable | ChannelResolvable, options?: MessageMentionsHasOptions): boolean;
public readonly members: Collection<Snowflake, GuildMember> | null; public readonly members: Collection<Snowflake, GuildMember> | null;
public repliedUser: User | null;
public roles: Collection<Snowflake, Role>; public roles: Collection<Snowflake, Role>;
public users: Collection<Snowflake, User>; public users: Collection<Snowflake, User>;
public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>; public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>;