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

268
Views
Void.delete() (discord.JS v13)

so I know the problem, I just dont know a solution for this. The console.log says: TypeError: msg.delete is not a function

I know msg is a void, so thats why it doesnt work.

Im thankful for every help!

My code looks like this:

message.channel.bulkDelete(messages);
        
message.channel.send("Messages getting purged...")
.then((sentMessage) => setTimeout(function () { 

sentMessage.edit(` **${amount}** messages were purged!`) 

}))
.then((msg) => setTimeout(function () { msg.delete() }, 6000)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The problem is msg is not the message you sent, but the timeout ID as you return it here: (sentMessage) => setTimeout().

Try to return the sentMessage so you an grab it in your next then():

message.channel
  .send('Messages getting purged...')
  .then(sentMessage => {
    setTimeout(function () {
      sentMessage.edit(` **${amount}** messages were purged!`);
    });
    return sentMessage;
  })
  .then(msg =>
    setTimeout(function () {
      msg.delete();
    }, 6000),
  );

It would be probably better to use async/await here though (just make sure you're inside an async function):

try {
  // send a message that messages are being deleted
  const sentMessage = await message.channel.send('Messages getting purged...');

  // delete the messages and wait for them to be deleted
  const deletedMessages = await message.channel.bulkDelete(messages);

  // edit the sent message when finished
  await sentMessage.edit(`**${deletedMessages.size}** messages were purged!`);

  // delete the message after 6 seconds
  setTimeout(() => sentMessage.delete(), 6000);
} catch (err) {
  message.channel.send(`Oops, there was an error`);
  console.log(err);
}
about 4 years ago · Juan Pablo Isaza Report

0

message.channel.bulkDelete(messages);
        
message.channel.send("Messages getting purged...")
.then((sentMessage) => setTimeout(function () { 

sentMessage.edit(`**${amount}** messages were purged!`).then((msg) => setTimeout(function () { msg.delete() }, 6000)

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