> For the complete documentation index, see [llms.txt](https://hk-yeet.gitbook.io/hkutilities/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hk-yeet.gitbook.io/hkutilities/creating-events.md).

# Creating Events

To create an event, you have to pass in the following parameters:

* Bot
* HKandler
* Whatever parameters are needed for the event

## Ready Event

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

```javascript
module.exports = (bot, hkandler) => {
  console.log(`Logged in as ${bot.user.tag} and my prefix is ${hkandler.prefix}`);
};
```

{% endcode %}
{% endtab %}

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

```typescript
import { Client } from "discord.js"
import { HKandler } from "hkutilities/dist/structures/hkandler"
module.exports = (bot: Client, hkandler: HKandler) => {
  console.log(`Logged in as ${bot.user.tag} and my prefix is ${hkandler.prefix}`);
};
```

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

## Message Event

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

```javascript
const { filter, errorEmbed } = require("hkutilities");
module.exports = (bot, hkandler, message) => {
  const { prefix } = hkandler;
  /*
  let's use the  filter to check if message is from a bot or the message is in dm's
  filter takes 1 paramter; message
  */
  if (filter(message) return;
  if (!message.content.startsWith(prefix)) return;
  const args = message.content.slice(prefix.length).trim().split(/ +/);
  const commandName = args.shift().toLowerCase();

  const command =
    hkandler.commands.get(commandName) ||
    hkandler.commands.find(
      (cmd) => cmd.aliases && cmd.aliases.includes(commandName)
    );
  if (!command) return;

  try {
    command.execute(bot, message, args, hkandler);
  } catch (error) {
    /*
    let's use the error embed function
    errorEmbed takes in 2 parameters; the channel, and the "error"
    */
    errorEmbed(message.channel, error);
  }
};
```

{% endcode %}
{% endtab %}

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

```typescript
import { filter, errorEmbed } from "hkutilities";
import { HKandler } from "hkutilities/dist/structures/hkandler"
import { Client, Message } from "discord.js" 
export = (bot: Client, hkandler: HKandler, message: Message) => {
  const { prefix } = hkandler;
  /*
  let's use the  filter to check if message is from a bot or the message is in dm's
  filter takes 1 paramter; message
  */
  if (filter(message) return;
  if (!message.content.startsWith(prefix)) return;
  const args = message.content.slice(prefix.length).trim().split(/ +/);
  const commandName = args.shift().toLowerCase();

  const command =
    hkandler.commands.get(commandName) ||
    hkandler.commands.find(
      (cmd) => cmd.aliases && cmd.aliases.includes(commandName)
    );
  if (!command) return;

  try {
    command.execute(bot, message, args, hkandler);
  } catch (error) {
    /*
    let's use the error embed function
    errorEmbed takes in 2 parameters; the channel, and the "error"
    */
    errorEmbed(message.channel, error);
  }
};
```

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