# buttonClick Event

## Button Clicks

When someone clicks on a button or uses a dropdown, it will fire an event called 'buttonClick'.

```javascript
client.on('buttonClick', async (button) => {
});
```

### Replying to buttons

We can reply when a button is clicked using `.reply()`.

```javascript
button.reply("");
```

If needed, you are able to add embeds, flags, attachments, and type in the reply. Check [Methods](/interactions/methods.md#interaction).

### Updating buttons

We can edit the original message that had the buttons using `.update()`.

```javascript
button.update("");
```

If needed, you are able to add embeds, flags, attachments, and type in the reply. Check [Methods](/interactions/methods.md#interaction).

## Examples

### Buttons

Here is an example of how to check for button IDs and how to handle them. [**Example**](https://github.com/GmBodhi/shandler-example-bot/blob/master/index.js#L29-L67)\*\*\*\*

```javascript
client.on('buttonClick', async (button) => {
    if (button.data.custom_id === "1") {

        button.reply("Heya!"); //Reply to the interaction.

    } else if (button.data.custom_id === "2") {

        button.update("Edited the button :)"); //This will edit the original message. 

    } else if (button.data.custom_id === "3") {

        button.reply("Heya!", { flags: 64 }); //This will reply to the interaction with an ephemeral message. 

    } else if (button.data.custom_id === "4") {

        let cmp = [
            {
                "type": 1, "components": [
                    { "type": 2, "style": 1, "label": "Button 1", "custom_id": "3" },
                ]
            }
        ];

        button.update("Buttons!", { components: cmp });

    };
});
```

### Dropdowns

Here is an example of how to check for dropdown information and how to handle them. [**Example**](https://github.com/GmBodhi/shandler-example-bot/blob/master/index.js#L68-L73)\*\*\*\*

```javascript
client.on('buttonClick', async (button) => {
    if (button.data.custom_id === "dropdown1") {

        if (button.data.values[0] === "hmmm") {

            button.reply(`🤔`)

        } else if (button.data.values[0] === "test") {

            button.reply(`Tests`)

        }
    };
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shandler.js.org/buttons/buttonclick-event.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
