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

168
Views
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 answers
Answer question

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 Report

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