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?
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 ...
});