Reputation: 23
I wrote a simple "say" command, but I'm trying to disable the mentioning of any role and/or user.
For example, If someone types "!say @everyone", the bot instead of replying with "@everyone" and tagging everyone, should reply with "You don't have permission!" or just execute the user's command but filtering out the @ before "everyone".
Here's my code:
module.exports = {
name: "say",
description: "Say command",
usage: "<msg>",
run: async (bot, message, args) => {
if (!message.member.permissions.has("MANAGE_MESSAGES")) return;
let MSG = message.content.split(`${bot.prefix}say `).join("");
if (!MSG)
return message.channel.send(`Non hai specificato il messaggio da inviare!`);
message.channel.send(MSG);
message.delete();
},
};
Can someone help me? Thank you in advance.
Upvotes: 0
Views: 4751
Reputation:
Just use allowedMentions
of messageOptions
when sending the message
// In discord.js V13, but this works on V12
message.channel.send({ content: "Hello @everyone", allowedMentions: { parse: [] }});
This will make the message output cleanly, the mention will still be seen as a mention but will not mention anyone.
Upvotes: 3
Reputation: 1
Or.. just add this on client options: (i'll show full example)
const Discord = require('discord.js')
const client = new Discord.Client({
disableMentions: "everyone", //THIS
intents: [
"GUILDS",
"GUILD_MESSAGES",
"GUILD_INTEGRATIONS",
"GUILD_VOICE_STATES",
"GUILD_MESSAGE_REACTIONS",
"DIRECT_MESSAGES"
] //optional
});
Upvotes: -1
Reputation: 228
Or if you want to remove mentions from message then you can use RegExp:
// If Message Content Includes Mentions
if (message.content.includes(/<@.?[0-9]*?>/g)) {
//Replace All Message Mentions Into Nothing
message = message.replace(/<@.?[0-9]*?>/g, "");
};
Explication:
we check if message content includes mention or not if yes then replace all mentions into nothing
Links:
Learn About RegExp
RegExp Source
Upvotes: 2