Slash command executed

Receive the event

After a user executed the command, you need to receive the interaction. You can use the following event

client.on("commandExecuted", cmd => {
    console.log(cmd)

    // Source...
})

To test it we'll reply with a text and a button

// Create a button
const button = new utils.Button({
    label: "You're right", // text that appears on the button, max 80 characters
    style: "green", // set the color (green, red, gray, blurple)
    ID: "my_id" // a developer-defined identifier for the button, max 100 characters
})

// Let the bot think
await cmd.think()

setTimeout(() => {
    // Response to the interaction with the button after 2.5 seconds
    cmd.reply({
        content: `You said you're feeling **${cmd.args.find(e => e.name == "feeling").value}**`, // adding the value of the "feeling" option
        components: [button], // add the button
        ephemeral: cmd.args.find(e => e.name == "ephemeral").value // response as an ephemeral if the user selected "yes"
    })
}, 2500)

At the end, it should looks like this

client.on("commandExecuted", cmd => {
    console.log(cmd)

    // Create a button
    const button = new utils.Button({
        label: "You're right", // text that appears on the button, max 80 characters
        style: "green", // set the color (green, red, gray, blurple)
        ID: "my_id" // a developer-defined identifier for the button, max 100 characters
    })
    
    // Response to the interaction with the button
    cmd.callback.post({
        content: `You said you're feeling **${cmd.args.find(e => e.name == "feeling").value}**`, // adding the value of the "feeling" option
        components: [button], // add the button
        ephemeral: cmd.args.find(e => e.name == "ephemeral").value // response as an ephemeral if the user selected "yes"
    })
})

Take a look on the next page, to see how you can receive the event when a user clicks on the button

Last updated