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

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

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 Denunciar

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 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