Search code examples
discord.js

Discord JS 12.5.3 messageUpdate have trouble


i added messageUpdate for my bot's modlogs like this:

c.on("messageUpdate", function(oldMessage, newMessage) {
      if (oldMessage.channel.type !== "text") return;
      if (newMessage.channel.type !== "text") return;

      if (oldMessage.content === newMessage.content) return;
      send_log(
        c,
        oldMessage.guild,
        "YELLOW",
        "Message UPDATED",
        `
**Author : ** <@${newMessage.author.id}>
**Date : ** <t:${parseInt(newMessage.createdTimestamp / 1000)}:R>
**Channel : ** <#${newMessage.channel.id}>
**Orignal Message : **
\`\`\`
${oldMessage.content.replace(/`/g, "'")}
\`\`\`
**Updated Message : **
\`\`\`
${newMessage.content.replace(/`/g, "'")}
\`\`\``
      );
    });

it worked fine for a few minutes: output image

then my bot got into exit status 1 because of this:

**Author : ** <@${newMessage.author.id}>
                                    ^

TypeError: Cannot read property 'id' of null
    at Client.<anonymous> (/home/runner/hibikibanmai-bot/events/client/logger.js:286:37)

Solution

  • Maybe add:

    if (!newMessage.author) return;