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

fix(messagementions): fix has method #7292

Merged
merged 15 commits into from
Jan 28, 2022
25 changes: 15 additions & 10 deletions packages/discord.js/src/structures/MessageMentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,22 @@ class MessageMentions {
* @returns {boolean}
*/
has(data, { ignoreDirect = false, ignoreRoles = false, ignoreEveryone = false } = {}) {
if (!ignoreEveryone && this.everyone) return true;
const { GuildMember } = require('./GuildMember');
if (!ignoreRoles && data instanceof GuildMember) {
for (const role of this.roles.values()) if (data.roles.cache.has(role.id)) return true;
const user = this.client.users.resolve(data),
Syjalo marked this conversation as resolved.
Show resolved Hide resolved
role = this.guild?.roles.resolve(data) ?? null,
channel = this.client.channels.resolve(data),
isDirect = user ?? role ?? channel;
Syjalo marked this conversation as resolved.
Show resolved Hide resolved

if (!ignoreDirect && isDirect) {
if (this.users.has(user?.id)) return true;
if (!ignoreRoles && this.roles.has(role?.id)) return true;
Syjalo marked this conversation as resolved.
Show resolved Hide resolved
if (this.channels.has(channel?.id)) return true;
}

if (!ignoreDirect) {
const id =
this.guild?.roles.resolveId(data) ?? this.client.channels.resolveId(data) ?? this.client.users.resolveId(data);

return typeof id === 'string' && (this.users.has(id) || this.channels.has(id) || this.roles.has(id));
if (user && !ignoreEveryone && this.everyone) return true;
Syjalo marked this conversation as resolved.
Show resolved Hide resolved
if (!ignoreRoles) {
const member = this.guild?.members.resolve(data) ?? null;
if (member) {
for (const mentionedRole of this.roles.values()) if (member.roles.cache.has(mentionedRole.id)) return true;
}
}

return false;
Expand Down