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

164
Visualizações
TypeError: Cannot read property 'delete' of undefined

I am getting an error (Cannot read property 'delete' of undefined). It's probably an easy fix but I can't seem to figure out how to fix it.

The error:

message.delete({timeout: 1000})

TypeError: Cannot read property 'delete' of undefined

My code:

const client = new Client();

let count = 0;
let timeout;

client.on('message', ({ channel, content, member, message }) => {
  if (channel.id === '933939208102494270') {
    if (member.user.bot) return;

    if (Number(content) === count + 1) {
      count++;

      if (timeout) clearTimeout(timeout);

      timeout = setTimeout(
        () => channel.send(++count).catch(console.error),

        100
      );
    } else if (member.id !== client.user.id) {
      message.delete({
        timeout: 1000,
      });
      channel.send(`${member} messed up!`).catch(console.error);
      message.delete({
        timeout: 1000,
      });

      //      count = 0

      if (timeout) clearTimeout(timeout);
    }
  }
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

of undefined

look left of this... so message is undefined, log what that is at the top of client.on, will find that message is undefined and thus delete does not exist.

about 4 years ago · Juan Pablo Isaza Relatório

0

The problem is that you try to destructure the first parameter of the callback, which is a Message object, and a Message doesn't have a message property. If you need the message, you can destructure it inside the function.

So instead of

client.on('message', ({ channel, content, member, message }) => {
  // ...

it should be

client.on('message', (message) => {
  let { channel, content, member } = message
  // ...

This way you can use any other property and method of the message.

about 4 years ago · Juan Pablo Isaza 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