Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
How could I make the setTimeout(function(){message.delete();} function delete a Discord Message Embed?

I'm getting into javascript, or more specifically discord.js and I've decided to try to make a moderation bot. I created a ban command, and after it bans the user, it sends a message embed showing the info of the ban, such as the reasoning of the ban, the user's tag, etc. I've decided to use the setTimeout function to delete the embed after 5 seconds. But, I can't figure out how to. I know exactly how to use the setTimeout function, it's just that I don't know what to do to delete the embed. Here's my code:

            let kickEmbed = new Discord.MessageEmbed()
            .setTitle('Member Kicked!')
            .setColor("GREEN")
            .addFields(
                {name: `Member:`, value: `${memberTarget}`},
                {name: `Moderator`, value: `${message.author}`},
                {name: `Reason`, value: `${kickReason}`}
            )
            await message.channel.send({embeds: [kickEmbed]})
            setTimeout(function(){
                kickEmbed.delete();
            }, 5000);

The problem is the "kickEmbed.delete();" part. I don't know what to put there. kickEmbed doesn't work, msg doesn't work, message doesn't work either. Here's an error if that helps: 'kickEmbed.delete' is not a function

Can anyone help me solve this?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

setTimeout(function(newArg) {
  newArg.delete();
}, 5000, KickEmbed);

I don't like making posts but first part to solution is understanding what you send to a timeout. If you send no arguments it's a global call and if that updates/changes or is removed errors in code occur so passing the value you intend on usage is optimal here. Second part is discord and its proper usage. GL

about 4 years ago · Juan Pablo Isaza Relatório

0

This is because you are running it on the MessageEmbed object itself. Make it so you save the sent message to a variable, rather than the embed object

let kickEmbed = new Discord.MessageEmbed()
            .setTitle('Member Kicked!')
            .setColor("GREEN")
            .addFields(
                {name: `Member:`, value: `${memberTarget}`},
                {name: `Moderator`, value: `${message.author}`},
                {name: `Reason`, value: `${kickReason}`}
            )
            let sentMessage = await message.channel.send({embeds: [kickEmbed]})
            setTimeout(function(){
                sentMessage.delete();
            }, 5000)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda