mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
add MessageMentions#has, remove old method (#1724)
* Update MessageMentions.js * remove old method * smh * Update Message.js * Update MessageMentions.js * Update MessageMentions.js * Update MessageMentions.js
This commit is contained in:
@@ -330,32 +330,6 @@ class Message {
|
||||
this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_MESSAGES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not a user, channel or role is mentioned in this message.
|
||||
* @param {GuildChannel|User|Role|string} data Either a guild channel, user or a role object, or a string representing
|
||||
* the ID of any of these
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMentioned(data) {
|
||||
data = data && data.id ? data.id : data;
|
||||
return this.mentions.users.has(data) || this.mentions.channels.has(data) || this.mentions.roles.has(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not a guild member is mentioned in this message. Takes into account
|
||||
* user mentions, role mentions, and @everyone/@here mentions.
|
||||
* @param {GuildMember|User} member The member/user to check for a mention of
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMemberMentioned(member) {
|
||||
// Lazy-loading is used here to get around a circular dependency that breaks things
|
||||
if (!GuildMember) GuildMember = require('./GuildMember');
|
||||
if (this.mentions.everyone) return true;
|
||||
if (this.mentions.users.has(member.id)) return true;
|
||||
if (member instanceof GuildMember && member.roles.some(r => this.mentions.roles.has(r.id))) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options that can be passed into editMessage.
|
||||
* @typedef {Object} MessageEditOptions
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const Collection = require('../util/Collection');
|
||||
const GuildMember = require('./GuildMember');
|
||||
|
||||
/**
|
||||
* Keeps track of mentions in a {@link Message}.
|
||||
@@ -115,6 +116,22 @@ class MessageMentions {
|
||||
}
|
||||
return this._channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user is mentioned. Takes into account user mentions, role
|
||||
* mentions, and @everyone/@here mentions.
|
||||
* @param {UserResolvable|GuildMember|Role|GuildChannel} data User/GuildMember/Role/Channel to check
|
||||
* @param {boolean} [strict=true] If role mentions and everyone/here mentions should be included
|
||||
* @returns {boolean}
|
||||
*/
|
||||
has(data, strict = true) {
|
||||
if (strict && this.everyone) return true;
|
||||
if (strict && data instanceof GuildMember) {
|
||||
for (const role of this.roles) if (data.roles.has(role.id)) return true;
|
||||
}
|
||||
const id = data.id || data;
|
||||
return this.users.has(id) || this.channels.has(id) || this.roles.has(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user