Scarmo
Scarmo

Reputation: 43

client.on('messageUpdate' ....) not working properly?

I'm trying to log when a user edits a message. Its not really working....

Here is my code:

client.on('messageUpdate', (oldMessage, newMessage) => {
    logMessageEdit(oldMessage, newMessage);
});

function logMessageEdit(oldMessage, newMessage) {

    if (!newMessage.guild.channels.find('name', "logs")) return;

    logChannel = newMessage.guild.channels.find('name', "logs");

    let logEmbed = new Discord.RichEmbed()
        .setAuthor(newMessage.author.tag, newMessage.author.avatarURL)
        .setDescription(`💬 | Meddelande redigerat i ${oldMessage.channel}.`)
        .addField("Innan", "test" + oldMessage.content)
        .addField("Efter", "test" + newMessage.content)
        .setTimestamp()
        .setFooter(newMessage.id)
        .setColor(greenColor);

    logChannel.send(logEmbed)
}

And here is what it results in:

Upvotes: 3

Views: 4395

Answers (1)

radiish
radiish

Reputation: 218

not too familiar with the client.on('messageUpdate') method but the bot is logging its own message sends, not just your messages. try updating your client.on('messageUpdate') method

client.on('messageUpdate', (oldMessage, newMessage) => {
    if(newMessage.author.id === client.user.id) return;
    logMessageEdit(oldMessage, newMessage);
});

if this doesn't work check for other calls of logMessageEdit such as in the client.on('message') event

Upvotes: 2

Related Questions