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

288
Views
How could I make the setTimeout(function(){message.delete();} function delete a Discord Message Embed?

I'm getting into javascript, or more specifically discord.js and I've decided to try to make a moderation bot. I created a ban command, and after it bans the user, it sends a message embed showing the info of the ban, such as the reasoning of the ban, the user's tag, etc. I've decided to use the setTimeout function to delete the embed after 5 seconds. But, I can't figure out how to. I know exactly how to use the setTimeout function, it's just that I don't know what to do to delete the embed. Here's my code:

            let kickEmbed = new Discord.MessageEmbed()
            .setTitle('Member Kicked!')
            .setColor("GREEN")
            .addFields(
                {name: `Member:`, value: `${memberTarget}`},
                {name: `Moderator`, value: `${message.author}`},
                {name: `Reason`, value: `${kickReason}`}
            )
            await message.channel.send({embeds: [kickEmbed]})
            setTimeout(function(){
                kickEmbed.delete();
            }, 5000);

The problem is the "kickEmbed.delete();" part. I don't know what to put there. kickEmbed doesn't work, msg doesn't work, message doesn't work either. Here's an error if that helps: 'kickEmbed.delete' is not a function

Can anyone help me solve this?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

setTimeout(function(newArg) {
  newArg.delete();
}, 5000, KickEmbed);

I don't like making posts but first part to solution is understanding what you send to a timeout. If you send no arguments it's a global call and if that updates/changes or is removed errors in code occur so passing the value you intend on usage is optimal here. Second part is discord and its proper usage. GL

about 4 years ago · Juan Pablo Isaza Report

0

This is because you are running it on the MessageEmbed object itself. Make it so you save the sent message to a variable, rather than the embed object

let kickEmbed = new Discord.MessageEmbed()
            .setTitle('Member Kicked!')
            .setColor("GREEN")
            .addFields(
                {name: `Member:`, value: `${memberTarget}`},
                {name: `Moderator`, value: `${message.author}`},
                {name: `Reason`, value: `${kickReason}`}
            )
            let sentMessage = await message.channel.send({embeds: [kickEmbed]})
            setTimeout(function(){
                sentMessage.delete();
            }, 5000)
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!