Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
events `messageUpdate` and `messageDelete` doesn't "work" after bot restart

Well, events messageUpdate and messageDelete doesn't "work" after restarting the bot

I mean, they don't respond to messages that were sent before the restart

I added MESSAGE to partials

Now the events works, but there is a problem with the if (newMessage.author.bot) return and if (message.author.bot) return and generally with message|newMessage.author|member etc.

Here are the error:

TypeError: Cannot read properties of null (reading 'bot')
    at module.exports.run (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\events\messageDelete.js:14:28)
    at Slodziak.<anonymous> (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\aslodziak.js:40:43)
    at Slodziak.emit (node:events:527:28)
    at Slodziak.emit (node:domain:475:12)
    at MessageDeleteAction.handle (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\node_modules\discord.js\src\client\actions\MessageDelete.js:24:16)
    at Object.module.exports [as MESSAGE_DELETE] (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_DELETE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\node_modules\discord.js\src\client\websocket\WebSocketManager.js:346:31)    at WebSocketShard.onPacket (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\node_modules\discord.js\src\client\websocket\WebSocketShard.js:478:22)        
    at WebSocketShard.onMessage (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\node_modules\discord.js\src\client\websocket\WebSocketShard.js:317:10)       
    at WebSocket.onMessage (C:\Users\ALL\Desktop\Slodziak\Slodziak13vCanary\node_modules\ws\lib\event-target.js:199:18)

Can someone help? I need these partials MESSAGE to messageUpdate because the bot did not respond to messages that were sent after restart. More specifically, to the automod, i.e. that it deletes invitations if someone has edited the message and has no permissions

messageUpdate

module.exports = class {
    constructor(client) {
        this.client = client;
    }

    async run(oldMessage, newMessage) {

        const data = {};
        const client = this.client;
        data.config = client.config;

        if (newMessage.author.bot) return;
        if (!newMessage.editedAt) return;

        code that deleted invites if member has not permissions

    }
};

messageDelete

module.exports = class {
    constructor(client) {
        this.client = client;
    }

    async run(message) {

        const data = {};
        const client = this.client;
        data.config = client.config;

        if (message.author.bot) return;

        Code that snipes deleted message
    
    }
}
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

The error means that newMessage.author is null. You already knew that you would need to use the MESSAGE partials.

The problem is that you don't check if the received message is a partial only.

A partial message will not contain all of the original Message parameters. The id, the channelId, and the guildId will be present, but others, like author, can be null.

To solve this, you'll need to check if your message is partial only, and if it is, you can fetch it and use it as usual:

module.exports = class {
  constructor(client) {
    this.client = client;
  }
  async run(oldMessage, newMessage) {
    const data = {};
    const client = this.client;
    data.config = client.config;
    
    if (oldMessage.partial) oldMessage = await oldMessage.fetch();
    if (newMessage.partial) newMessage = await newMessage.fetch();

    if (newMessage.author.bot) return;
    if (!newMessage.editedAt) return;

    // code that deleted invites if the member has no permissions
  }
};
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!