Is your feature request related to a problem? Please describe.
The disableMentions function is missing a feature for me. Using all breaks all mentions, but using everyone does still mention roles that can only be mentioned with the MENTION_EVERYONE permission.
Describe the ideal solution
Ideally using disableMentions:'everyone' would also escape mentions of non-mentionable roles.
Describe alternatives you've considered
Adding a fourth option for disableMentions would of course work as well but probably requires more coding.
Additional context
I wrote myself I small function to escape the mentions, maybe that could be used in some way.
function cleanRestrictedMentions(text, message) {
return text.replace( /@(here|everyone)/g, '@\u200b$1' ).replace( /<@&(\d+)>/g, (mention, id) => {
if (message.channel.type === 'dm') return mention;
var role = message.guild.roles.cache.get(id);
return ( role && !role.mentionable ? `@${role.name}` : mention );
} );
}
Role.mentionable is based on the toggle for the role, not if the bot has mention everyone permissions, so that would yield the same result, and the first regex was removed in the first place as it was unreliable, see #3830
Role.mentionable is based on the toggle for the role, not if the bot has mention everyone permissions
That's exactly the point though. If the role isn't mentionable, you probably want a way to prevent the bot from accidentally mentioning it because it has MENTION_EVERYONE.
But in the case of example code provided in opening post, Role.mentionable on itself does not accurately reflect if the bot will actually mention the role, since it is ignored if bot has mention everyone permission.
Eventual check would probably look like if (bot has mention everyone && role is not mentionable), and if that's true escape the role mention.
The current disableMentions:everyone doesn't check if the bot has mention everyone permission either, so I didn't add one. I also don't think a permissions check would really be necessary as users can easily add one themselves when adding the disableMentions option or just always stay on the save side.
users can easily add one themselves when adding the disableMentions option
But that defeats the purpose of having disableMentions, if you have to remember to "tighten up" the message content checks by yourself
True, but then a permissions check would need to be added to the current disableMentions:'everyone' as well. And the disableMentions option would return an inconsistent result with sometimes escaping mentions and sometimes not depending on the permission. I think having the same option always return the same text independent from the permission would be better.
Example:
Using message.channel.send(`${role}`,{disableMentions:'everyone'}) on two different channels of the same guild. Channel A has a channel overwrite allowing the bot to mention everyone, channel B does not. Channel B has the role mention highlighted while channel A does not. That would be inconsistent and confusing to debug as the permission check is not obvious.
[...] but using
everyonedoes still mention roles that can only be mentioned with theMENTION_EVERYONEpermission.
Bots currently do not have "access" to this new feature where users with the MENTION_EVERYONE permission can actually mention roles that are not marked as "mentionable".
See this Reddit post for more info.
So this is, at least currently, not an issue.
On another note, Discord is "working on exposing a new set of fields you can provide when you create a message or post a webhook that will specify what kinds of mentions will be allowed to be processed in a message. " (from https://github.com/discordapp/discord-api-docs/issues/1286#issuecomment-592865198)
Making this feature, hopefully soon, obsolete.
The above mentioned feature is live and I linked the relevant PR ^.
Most helpful comment
Bots currently do not have "access" to this new feature where users with the
MENTION_EVERYONEpermission can actually mention roles that are not marked as "mentionable".See this Reddit post for more info.
So this is, at least currently, not an issue.
On another note, Discord is "working on exposing a new set of fields you can provide when you create a message or post a webhook that will specify what kinds of mentions will be allowed to be processed in a message. " (from https://github.com/discordapp/discord-api-docs/issues/1286#issuecomment-592865198)
Making this feature, hopefully soon, obsolete.