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)
}
})
})
>Solution :
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)
}
})