Skip to content

Commit

Permalink
feat(MessageMentions): add repliedUser (#5905)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaporoxx authored Jun 25, 2021
1 parent 5af2ef5 commit 2616125
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion src/structures/MessageMentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1492,9 +1493,10 @@ declare module 'discord.js' {
export class MessageMentions {
constructor(
message: Message,
users: unknown[] | Collection<Snowflake, User>,
users: APIUser[] | Collection<Snowflake, User>,
roles: Snowflake[] | Collection<Snowflake, Role>,
everyone: boolean,
repliedUser?: APIUser | User,
);
private _channels: Collection<Snowflake, Channel> | null;
private readonly _content: string;
Expand All @@ -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<Snowflake, GuildMember> | null;
public repliedUser: User | null;
public roles: Collection<Snowflake, Role>;
public users: Collection<Snowflake, User>;
public crosspostedChannels: Collection<Snowflake, CrosspostedChannel>;
Expand Down

0 comments on commit 2616125

Please sign in to comment.