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

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

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 Denunciar

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