> For the complete documentation index, see [llms.txt](https://tribui141108.gitbook.io/nocli-handler.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tribui141108.gitbook.io/nocli-handler.js/guides/commands/guild-and-owner-only-commands.md).

# Guild and Owner-only Commands

## Setting up a `guildonly` Command

We will use the `ping` command as an example. Set `guildonly` to `true` if you want the `ping` command to work only in guilds.

{% tabs %}
{% tab title="JavaScript" %}
{% code title="ping.js" %}

```javascript
const { NoCliCommandType } = require("nocli-handler.js");

/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    guildOnly: true, // <-- Set guildOnly to true
    type: NoCliCommandType.Both,
    description: "Checks client latency",
    callback: ({ client, message, args, text }) => {
        return `🏓 Pong! \`${client.ws.ping}ms\``;
    }
}

module.exports = Command;
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="ping.ts" %}

```typescript
import { ICommand, NoCliCommandType } from "nocli-handler.js";

export default {
    guildOnly: true, // <-- Set guildOnly to true
    description: "Checks client latency",
    type: NoCliCommandType.Both,
    callback: ({ client, message, args, text }) => {
        return `🏓 Pong! \`${client.ws.ping}ms\``;
    }
} as ICommand;
```

{% endcode %}
{% endtab %}
{% endtabs %}

> ### End Result:
>
> In a **Server**:
>
> ![](/files/dzjGCy89bheXb8xmGBUJ)
>
> In a **Direct Message**:
>
> ![](/files/YbfqNYTOiU98hZ8gT0eq)

## Setting up a `ownerOnly` command

{% hint style="info" %}
`ownerOnly` option requires you to insert an array of IDs for `botOwners` option (which is mentioned on the [Setting Up Your Project](/nocli-handler.js/getting-started/setting-up-your-project.md) page).
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}
{% code title="ping.js" %}

```javascript
/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    ownerOnly: true, // <-- Set ownerOnly to true
    slash: "both",
    description: "Checks client latency",
    callback: ({ client, message, args, text }) => {
        return `🏓 Pong! \`${client.ws.ping}ms\``;
    }
}

module.exports = Command;
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="ping.ts" %}

```typescript
import { ICommand } from "nocli-handler.js";

export default {
    ownerOnly: true, // <-- Set ownerOnly to true
    description: "Checks client latency",
    slash: "both",
    callback: ({ client, message, args, text }) => {
        return `🏓 Pong! \`${client.ws.ping}ms\``;
    }
} as ICommand;
```

{% endcode %}
{% endtab %}
{% endtabs %}

> ### End Result:
>
> For **Normal User:**
>
> ![](/files/iti5G1Vp10KlkRzfbBZg)
>
> For **Bot Owner:**
>
> ![](/files/z44gpe5Li09UvSvJgxt9)


---

# 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:

```
GET https://tribui141108.gitbook.io/nocli-handler.js/guides/commands/guild-and-owner-only-commands.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.
