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

213
Vistas
How to clear previous Discord.MessageEmbed data in Discord.js

I'm trying to make a snipe command for the dc bot but I can't get the embed to reset. Tried putting embed = {} in different locations, then it tries sending an empty message the next time and errors out. Also it's let embed now since I was testing, tried const first. Edit: works now when checking messages elsewhere, should have done that to start with. Code:

bot.on('messageDelete', message => {
        let embed = new Discord.MessageEmbed()
          .setAuthor(`${message.author.username} (${message.author.id})`, message.author.avatarURL())
          .setDescription(message.content || "None")
          
          bot.on('message', message => {
          const args = message.content.slice(PREFIX.length).split(/ +/);

          const cmd = args.shift().toLowerCase();
      
              if (cmd === 'msg'){
                message.channel.send(embed)
                }
              
            })

      })
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You don't need a embed = {}, instead use client.snipes = new Map() as collector. So if someone delete message when the bot online, the bot can detect it.

client.snipes = new Map()
client.on('messageDelete', function(message, channel) {
    client.snipes.set(message.channel.id, {
        content: message.content,
        author: message.author,
        image: message.attachments.first() ? message.attachments.first().proxyURL : null
    })
}) //This will be your collector on your index file.

Then create a command file.

const msg = client.snipes.get(message.channel.id)
      if(!msg) return message.channel.send("Didn't find any deleted messages.")
        
      const embed = new MessageEmbed()
      .setDescription(`Your_Message`)
      .setTimestamp()
        
      if(msg.image) embed.setImage(msg.image) //If image deleted, it will go here.
      message.channel.send({ embeds: [embed] })
about 4 years ago · Juan Pablo Isaza Denunciar

0

Every time a message is deleted you are resubscribing to the message event. I would suggest taking some of that logic to the outside of that scope.

let embed = null;

bot.on('messageDelete', message => {
    embed = new Discord.MessageEmbed()
        .setAuthor(`${message.author.username} (${message.author.id})`, message.author.avatarURL())
        .setDescription(message.content || "None")
})

bot.on('message', message => {
    const args = message.content.slice(PREFIX.length).split(/ +/);
    const cmd = args.shift().toLowerCase();

    if (cmd === 'msg' && embed){
        message.channel.send(embed)
    }
})
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