> For the complete documentation index, see [llms.txt](https://docs.wornoffkeys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wornoffkeys.com/commands/command-initialization-method.md).

# Command initialization method

{% embed url="<https://youtu.be/_67r4wq23BA?t=402>" %}

Some commands may require you to run code when they are loaded. You can use the `init()` method within your command to handle this type of functionality:

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

```javascript
const { CommandType } = require("wokcommands");

module.exports = {
  description: "Ping pong command",
  type: CommandType.BOTH,

  init: (client, instance) => {
    console.log("Ping command has been loaded");
  },

  callback: () => {
    return {
      content: "Pong!",
    };
  },
};
```

{% endcode %}
{% endtab %}

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

```typescript
import { Client } from "discord.js";
import WOKCommands, { CommandObject, CommandType } from "wokcommands";

export default {
  description: "Ping pong command",
  type: CommandType.BOTH,

  init: (client: Client, instance: WOKCommands) => {
    console.log("Ping command has been loaded");
  },

  callback: () => {
    return {
      content: "Pong!",
    };
  },
} as CommandObject;
```

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