How to detect if a message is edited?

Brandon picture Brandon · Apr 8, 2018 · Viewed 8.1k times · Source

I am intending for my bot to allow only "ew" to be sent in chat. I have resolved majority of the work-arounds, however, there is one I can't resolve independently. When someone posts "ew" in chat and then edits the message to something else, it remains like that without being deleted.

How could I resolve this?

Answer

André picture André · Apr 8, 2018

client.on('messageUpdate') should trigger everytime a message (in cache) is edited. I'm pretty sure you will not get the event if the message was sent when the bot was offline. But you could fetch the messages when the bot starts.

client.on('messageUpdate', (oldMessage, newMessage) => {
   if(newMessage.content != "ew"){
       //dosomething
   }
}