> For the complete documentation index, see [llms.txt](https://dbd-ts.gitbook.io/dbdts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dbd-ts.gitbook.io/dbdts/guides/context-menus.md).

# Context Menus

Context menus are a new, cool way to for users to interact with your bot. Context menus can be accessed by right clicking or tapping on messages/users. They're a great way to surface quick actions for your bot that target messages/users.

{% hint style="success" %}
Don't forget to add the `onInteraction` event to your main file. For example:

```javascript
bot.addEvent([
    "onMessage",
    "onInteraction"
])
```

{% endhint %}

### Creating Application Command Data

To create a context menu application, you can use the `createApplicationCommandData` method in bot class:

**Template:**

```javascript
bot.createApplicationCommandData({
    type: "type",
    name: "name"
})
```

> [View Context Menu Types](/dbdts/typedefs/applicationcommandtypes.md)

{% hint style="warning" %}
There can be 5 guild and 5 global context menu commands per bot.
{% endhint %}

**Example:**

```javascript
bot.createApplicationCommandData({
    type: "USER",
    name: "Punch"
})
```

### Creating a Context Menu

Deploy this context menu to a guild (or globally).

**Template:**

```javascript
bot.commands.add({
    name: "deploy",
    type: "basicCommand",
    code: `$if[$botOwnerID!==$authorID;
            You can't use this command!
        ;
            $createContextMenuApplication[guildID/global;contextMenuName]
            Successfully created context menu app!
        ]`
})
```

**Example:**

```javascript
bot.commands.add({
    name: "deploy",
    type: "basicCommand",
    code: `$if[$botOwnerID!==$authorID;
            You can't use this command!
        ;
            $createContextMenuApplication[$guildID;Punch]
            Successfully created context menu app!
        ]`
})
```

### Responding to Context Menu Interactions

To respond to an interaction of a context menu, you can use the `contextMenuCommand` type.

**Template:**

```javascript
bot.commands.add({
    type: "contextMenuCommand",
    name: "name",
    code: `$reply
Hello World`
})
```

**Example:**

```javascript
bot.commands.add({
    type: "contextMenuCommand",
    name: "Punch",
    code: `$reply
        $username wants to punch <@$slashOption[user]>!`
})
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://dbd-ts.gitbook.io/dbdts/guides/context-menus.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
