Why does messageUpdate and messageDelete get triggered multiple times?

Viewed 690

I'm trying to make logs for my server, so when someone sends, deletes or edits a message, the bot will send an embed message in a specific channel with all the information. For some reason, the messageUpdate and messagedDelete events are triggered multiple times, and I can't understand why. I have tried everything, but nothing works. Why does this happen and how can I fix it?

I have the logs for each thing (sent, edited, deleted) in individual files, by the way. In my main file, this is the code I have for the messageUpdate:

bot.on('messageUpdate', (oldMessage, newMessage) => {

    if (oldMessage.author.id === bot.user.id) return;
    if(oldMessage.content === newMessage.content) return;
    
    bot.events.get('editlogs').execute(oldMessage, newMessage);
    
})

This is my code for the edit logs:

const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login(process.env.TOKEN);

module.exports = {

    name: 'editlogs',
    description: 'logs messages that were edited.',
    category: 'logs',
    execute(oldMessage, newMessage){
    
        const logsChannel = bot.channels.cache.get("743142195594526822")
        
        const logEmbed = new Discord.MessageEmbed()
        .setColor('#ffa600')
        .setTitle('Message Edited')
        .setAuthor(oldMessage.author.tag, oldMessage.author.avatarURL())
        .setThumbnail(oldMessage.author.avatarURL())
        .addFields(
            { name: 'Old Message', value: oldMessage.content},
            { name: 'New Message', value: newMessage.content},
            { name: 'Channel', value: oldMessage.channel.toString(), inline: true  },
            { name: 'Author', value: oldMessage.author, inline: true  },
            { name: 'Author ID', value: oldMessage.author.id},
            { name: 'Message ID', value: oldMessage.id},
            { name: 'Message', value: '[Jump To Message](' + oldMessage.url + ')'},
        )
        .setTimestamp()
        .setFooter('Edited in ' + oldMessage.guild.toString(), oldMessage.guild.iconURL());

        logsChannel.send(logEmbed);
    
        }}

0 Answers
Related