# Creating a simple "Ping Pong" Command

{% hint style="warning" %}
Before creating a command, please make sure you have specified a **commands directory** with the **correct syntax** as shown in the [Setting Up Your Project](/nocli-handler.js/getting-started/setting-up-your-project.md) page.&#x20;
{% endhint %}

### How to create a "Ping Pong" Command

{% tabs %}
{% tab title="JavaScript" %}
**Firstly**, create a file in the commands directory you specified in the **index.js** file, and name it **ping.js**.

![](/files/oBEr4C0zBq79zfh85MNQ)

**Secondly**, paste this code into your **ping.js** file.

{% code title="ping.js" %}

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

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

module.exports = Command;
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
Firstly, create a file in the commands directory you specified in the **index.ts** file, and name it **ping.ts**.

![](/files/hecqSEjgONh1heGdt0hB)

**Secondly**, paste this code into your **ping.ts** file.

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

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

export default {
    type: NoCliCommandType.Legacy,
    description: "Ping",
    callback: ({ client, message, args, text }) => {
        return `🏓 Pong! \`${client.ws.ping}ms\``;
    }
} as ICommand;
```

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

{% hint style="info" %}
You may receive a warning from the console that says `No mongoURI provided`. Just ignore that warning since this command doesn't require a database.
{% endhint %}

Once your program starts, try running the ping command:

![](/files/igIHn0zm0Ylnj4Ile5Cb)

For the default prefix during the nocli-handler.js initialization, if you have set any, please replace "!" with the default prefix you have set.


---

# 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://tribui141108.gitbook.io/nocli-handler.js/guides/commands/creating-a-simple-ping-pong-command.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.
