Hi there!
My bot has a logging system which logs any edited messages into a predefined log channel. For normal messages that only include text, my current code works great. However, any message that includes a link that Discord automatically turns into an embed (such as the one below) will trigger the message update event and send the message to the log channel.
The above Discord message will trigger the bot and it will send a log message where the Original message is exactly the same as the New message (see image below for output.)
This is a problem because the actual text hasn’t been updated, thus no need for the event to send a log message.
I have tried adding this line of code:
if (oldMessage == newMessage) return;
with the idea that if the original message is the same as the new message, the bot will ignore it but sadly this didn’t work and I’m really confused as to why.
Any help with this would be much appreciated! Below is my current code for the message update event.
client.on("messageUpdate", (oldMessage, newMessage) => {
if (oldMessage.guild.id != config.lcoz) return;
if (oldMessage.author.bot) return;
if (oldMessage == newMessage) return;
fs = require("fs");
fs.readFile("logs", "utf8", (err, data) => {
if (err) {
console.log("Error reading logs file!");
console.log(err);
}
if (data == "on") {
channel = client.channels.cache.get(config.logchannel);
const Embed = new MessageEmbed()
.setColor("#FF0000")
.setTitle(":hammer: Message Updated:")
.addField("**Member:**", oldMessage.author)
.addField("**Channel:**", oldMessage.channel)
.addField("**:pencil: Original message:**", oldMessage, true)
.addField("**:pencil: New message:**", newMessage, true)
.setThumbnail(oldMessage.author.displayAvatarURL({ dynamic: true }))
.setTimestamp()
.setFooter("Luck's Chill-Out Zone", "https://luckunstoppable7.com/media/logo.png");
channel.send(Embed);
}
});
});