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

1.2K
Visualizações
Is there a way to delete the response of a slash command [Discord.js]

My code is:

client.ws.on('INTERACTION_CREATE', async interaction => {
        const command = interaction.data.name.toLowerCase();
        const args = interaction.data.options;

        if (command === 'test'){ 
        console.log("Test executed")
        
        client.api.interactions(interaction.id, interaction.token).callback.post({
            data: {
                type: 4,
                data: {
                    content: "Check"
                }
            }
        })
    }
});

I want to delete the answer but I don't really understand how (Very new to this discord.js thing xd)

I saw this post but can't make the answer work

Can anybody please help :(

EDIT: Is it also possible to have a cooldown for a slash command?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

To delete a reply to an interaction (according to Discord Developer Portal) with discord.js v12 use the following:

client.api.webhooks(client.user.id, interaction.token)
    .messages("@original").delete();

Is it also possible to have a cooldown for a slash command?

Yes, it is definitely possible. It should be very similar to cooldowns for non-slash commands. Here you can take a look at this post, very simple cooldown system. Or here you have something more complex.

Here you can have a look at my simple and far from perfect example concerning cooldown system for slash commands:

const cooldowns = new Set();

client.ws.on("INTERACTION_CREATE", (interaction) => {

    const userId = interaction.member.user.id;
    const commandName = interaction.data.name.toLowerCase();
    
    const cooldownId = `${commandName}_${userId}`;
    const cooldownDuration = 60000; // 60 000 ms = 1 minute

    if (cooldowns.has(cooldownId)) {
        // There is a cooldown, notify user and return
        client.api.interactions(interaction.id, interaction.token).callback.post({
            data: {
                type: 4,
                data: {
                    content: "Wait 1 minute before typing this again!",
                    flags: 64, // make reply ephemeral
                }
            }
        });
        return;
    }

    // Create cooldown for next use
    cooldowns.add(cooldownId);
    setTimeout(() => { // Schedule cooldown deletion
        cooldowns.delete(cooldownId);
    }, cooldownDuration);

    // ... Execute the command ...

});
over 4 years ago · Santiago Trujillo 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