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

260
Views
DiscordJS, Delete previous embed message after receiving slash command

I have a bot that sends an embed message after receiving a /xyz with something like this

    client.on("interactionCreate", async (interaction) => {
      if (!interaction.isCommand()) return;
    
      const { commandName } = interaction;
    
      if (commandName === "xyz") {

         const embed = {
          title: "title of embed message",
          description: "description of embed message",
          ....
          }

    await interaction.channel.send({ embeds: [embed] });  
}

I would like to know how to delete the previous embed messages the bot sent, before sending a new one after receiving the /xyz command

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

0

Set a variable on the outer scope that you will assign when sending the embeds. Delete it whenever the command is run

let embedBefore;
client.on("interactionCreate", async (interaction) => {
      if (!interaction.isCommand()) return;
    
      const { commandName } = interaction;
    
      if (commandName === "xyz") {
         await embedBefore?.delete().catch(console.error) // delete the embed, catch and log error if thrown
         const embed = {
          title: "title of embed message",
          description: "description of embed message"
          }
        // assign embedBefore to the sent embed; Note: this is not an interaction reply
        embedBefore = await interaction.channel.send({ embeds: [embed] });
    }
})

The embed will stay there when the bot is restarted and the command is run again

about 4 years ago · Juan Pablo Isaza Report

0

You could store the previous embed(s) (there should only be one, right, since you delete the previous ones...) in something like a Set if you have multiple embeds somehow and then before you send your response iterate over the Set and invoke the delete() method on the stored messages. Here the documentation for Sets in case you need further info.

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!