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

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

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