Skip to content

Commit 7a52785

Browse files
ImRodryalmeidxSyjalo
authoredMar 6, 2022
fix(messagementions): fix has method for v13 (#7591)
Co-authored-by: Almeida <almeidx@pm.me> Co-authored-by: Synbulat Biishev <syjalo.dev@gmail.com>
1 parent 13dd82d commit 7a52785

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed
 

‎src/structures/MessageMentions.js

+20-13
Original file line numberDiff line numberDiff line change
@@ -173,28 +173,35 @@ class MessageMentions {
173173
* @typedef {Object} MessageMentionsHasOptions
174174
* @property {boolean} [ignoreDirect=false] Whether to ignore direct mentions to the item
175175
* @property {boolean} [ignoreRoles=false] Whether to ignore role mentions to a guild member
176-
* @property {boolean} [ignoreEveryone=false] Whether to ignore everyone/here mentions
176+
* @property {boolean} [ignoreRepliedUser=false] Whether to ignore replied user mention to an user
177+
* @property {boolean} [ignoreEveryone=false] Whether to ignore `@everyone`/`@here` mentions
177178
*/
178179

179180
/**
180-
* Checks if a user, guild member, role, or channel is mentioned.
181-
* Takes into account user mentions, role mentions, and `@everyone`/`@here` mentions.
181+
* Checks if a user, guild member, thread member, role, or channel is mentioned.
182+
* Takes into account user mentions, role mentions, channel mentions,
183+
* replied user mention, and `@everyone`/`@here` mentions.
182184
* @param {UserResolvable|RoleResolvable|ChannelResolvable} data The User/Role/Channel to check for
183185
* @param {MessageMentionsHasOptions} [options] The options for the check
184186
* @returns {boolean}
185187
*/
186-
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreEveryone = false } = {}) {
187-
if (!ignoreEveryone && this.everyone) return true;
188-
const { GuildMember } = require('./GuildMember');
189-
if (!ignoreRoles && data instanceof GuildMember) {
190-
for (const role of this.roles.values()) if (data.roles.cache.has(role.id)) return true;
191-
}
188+
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreRepliedUser = false, ignoreEveryone = false } = {}) {
189+
const user = this.client.users.resolve(data);
190+
const role = this.guild?.roles.resolve(data);
191+
const channel = this.client.channels.resolve(data);
192192

193+
if (!ignoreRepliedUser && this.users.has(this.repliedUser?.id) && this.repliedUser?.id === user?.id) return true;
193194
if (!ignoreDirect) {
194-
const id =
195-
this.guild?.roles.resolveId(data) ?? this.client.channels.resolveId(data) ?? this.client.users.resolveId(data);
196-
197-
return typeof id === 'string' && (this.users.has(id) || this.channels.has(id) || this.roles.has(id));
195+
if (this.users.has(user?.id)) return true;
196+
if (this.roles.has(role?.id)) return true;
197+
if (this.channels.has(channel?.id)) return true;
198+
}
199+
if (user && !ignoreEveryone && this.everyone) return true;
200+
if (!ignoreRoles) {
201+
const member = this.guild?.members.resolve(data);
202+
if (member) {
203+
for (const mentionedRole of this.roles.values()) if (member.roles.cache.has(mentionedRole.id)) return true;
204+
}
198205
}
199206

200207
return false;

‎typings/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5158,6 +5158,7 @@ export interface MessageInteraction {
51585158
export interface MessageMentionsHasOptions {
51595159
ignoreDirect?: boolean;
51605160
ignoreRoles?: boolean;
5161+
ignoreRepliedUser?: boolean;
51615162
ignoreEveryone?: boolean;
51625163
}
51635164

0 commit comments

Comments
 (0)
Please sign in to comment.