0

So far the questions I've seen were about deleting the whole message when a specific word is detected. What I need is to just edit the message and delete the specific letter, word, or emoji. How to do that?

So for example I have a message content saying "Awesome ❤️", and I want to delete ❤️ character only from the message, so it should be "Awesome".

client.on("messageCreate", (message) => {
if(message.content.includes("❤️")) {
//delete the ❤️ emoji only
}
})
user874737
  • 469
  • 1
  • 9
  • 24
  • 1
    Does this answer your question? [How do I remove emoji from string](https://stackoverflow.com/questions/24672834/how-do-i-remove-emoji-from-string) – Jay Nov 14 '22 at 12:02

2 Answers2

1

Just using replace can do it

let message = 'Awesome ❤️ Stackoverflow'
message = message.replace('❤️','')
console.log(message)
flyingfox
  • 13,414
  • 3
  • 24
  • 39
1

You can achieve this by removing all non ASCII characters out of the string:

function removeSpecialChars(str) {  
  str = str.toString();  
  return str.replace(/[^\x20-\x7E]/g, '');
}
janfitz
  • 1,183
  • 12
  • 21