keisi
keisi

Reputation: 3

removing mentions (discord.js 12.5.3)

I need to remove a user mention from message content, but nothing works. Discord.js version: 12.5.3

var content = message.content.toLowerCase().slice(6).trim().replace(/@(everyone)/gi, "@evеryone").replace(/@(here)/gi, "@hеre");
   !message.content.trim().endsWith('-test');

   if (message.mentions.users.size) {
      const mentioned = message.mentions.users.first();
      content.replace(``, '') // here is a problem
      var form = `${content}`;
   } else {
      doSomething()
   }
message.channel.send(form);

Upvotes: 0

Views: 781

Answers (2)

Maybe Lindow
Maybe Lindow

Reputation: 333

Try This

if(message.content.toLowerCase().includes("@")) {
message.delete()
message.reply("Do Not Ping!")
}

Upvotes: 0

Christoph Blüm
Christoph Blüm

Reputation: 975

Its really simple actually. Discord.js has its own function for that: Util.cleanContent()

You can replace all your code with this one-liner:

message.channel.send(discord.Util.cleanContent(message.content, message))

or (as @MrMythical rightfully mentioned):

return message.reply(message.cleanContent)

The message still looks the same, just without the pings.

Upvotes: 3

Related Questions