# Quick Start

## How to install

{% tabs %}
{% tab title="npm" %}

```sh
npm i djs-protofy
```

{% endtab %}

{% tab title="yarn" %}

```sh
yarn add djs-protofy
```

{% endtab %}

{% tab title="pnpm" %}

```sh
pnpm add djs-protofy
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
The code below must be located in the main file of your application, usually called *index* or *main*
{% endhint %}

{% hint style="info" %}
If you use sharding, you must place the code below in the main client file, not in the ShardingManager
{% endhint %}

{% tabs %}
{% tab title="ES5" %}

```javascript
require("djs-protofy/init");
```

{% endtab %}

{% tab title="ES6" %}

```typescript
import "djs-protofy/init";
```

{% endtab %}
{% endtabs %}

## JavaScript and TypeScript

{% tabs %}
{% tab title="JavaScript" %}

```javascript
require("djs-protofy/init");
const { ChannelType, Client, GatewayIntentBits } = require("discord.js");

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.on("messageCreate", async (message) => {

  if (message.content === "-ping") {
    const channel = client.channels.getById(string, ChannelType.GuildText);
    if (channel) await channel.send({ content: "pong" });
  }

});

client.login();
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import "djs-protofy/init";
import { ChannelType, Client, GatewayIntentBits } from "discord.js";

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.on("messageCreate", async (message) => {

  if (message.content === "-ping") {
    const channel = client.channels.getById(string, ChannelType.GuildText);
    if (channel) await channel.send({ content: "pong" });
  }

});

client.login();
```

{% endtab %}
{% endtabs %}

## Using with sharding

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

```javascript
require("dotenv/config");
const { ShardingManager } = require("discord.js");

const manager = new ShardingManager("shard.js");

manager.spawn();
```

{% endcode %}

{% code title="/shard.js" %}

```javascript
require("djs-protofy/init");
const { Client, GatewayIntentBits } = require("discord.js");

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.on("ready", () => {
  console.log("ready");
  
  client.users.getById(string); // User | undefined
});

client.login();
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="/sharding.ts" %}

```typescript
import "dotenv/config";
import { ShardingManager } from "discord.js";

const manager = new ShardingManager("shard.js");

manager.spawn();
```

{% endcode %}

{% code title="/shard.ts" %}

```typescript
import "djs-protofy/init";
import { Client, GatewayIntentBits } from "discord.js";

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.on("ready", () => {
  console.log("ready");
  
  client.users.getById(string); // User | undefined
});

client.login();
```

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