Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda