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(MessageMentions): add repliedUser #5905

Merged
merged 2 commits into from Jun 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/structures/Message.js
Expand Up @@ -180,7 +180,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 @@ -314,6 +321,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
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
vaporoxx marked this conversation as resolved.
Show resolved Hide resolved
* @type {?User}
*/
this.repliedUser = repliedUser ? this.client.users.add(repliedUser) : null;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion typings/index.d.ts
Expand Up @@ -140,6 +140,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 @@ -1467,9 +1468,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 @@ -1481,6 +1483,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