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

217
Views
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 answers
Answer question

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 Report

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