Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda