Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

update(docs on sharding) #146

Open
wants to merge 4 commits into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [Custom Events](advanced-guides/custom-events.md)
* [@akarui/aoi.music](advanced-guides/music.md)
* [dbd.express](advanced-guides/dashboard.md)
* [Sharding](advanced-guides/sharding.md "guide on sharding")

***

Expand Down Expand Up @@ -558,7 +559,6 @@
## Other

* [Hyperlink](other/hyperlink.md)
* [Sharding](other/sharding.md)
* [Character Escaping](other/character-escaping.md)
* [Embed Errors](other/embed-errors.md)
* [Permissions](other/permissions.md)
Expand Down
95 changes: 95 additions & 0 deletions src/advanced-guides/sharding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Sharding

## Introduction

aoi.js has `ClientShard` class to handle `Sharding` for your discord bot.

## Usage

```ts
const sharder: ClientShard = new ClientShard(
file: string,
sharderOptions?: ShardOption,
spawnOptions?: SpawnOption
)
```

### file

<table>
<tr>
<th>Type</th>
<td>string</td>
</tr>
<tr>
<th>Description</th>
<td>Path to bot file</td>
</tr>
<tr>
<th>Required</th>
<td>yes</td>
</tr>
<tr>
<th>Default</th>
<td>N/A</td>
</tr>
</table>

### sharderOptions

| Property | Type | Description | Required | Default |
| ---------------- | ------------------ | -------------------------------------------------------- | -------- | ------- |
| **_totalShard_** | string \| number | number of total Shards | no | auto |
| **_shardList_** | string \| number[] | List of Shards to spawn | no | auto |
| **_mode_** | process \| worker | type of Sharding Mode (child_process \| worker_threads ) | no | process |
| **_respawn_** | boolean | whether to respawn shards on exiting | no | true |
| token | string | token to use for shard count | no | none |

### spawnOptions

| Property | Type | Description | Required | Default |
| ------------- | ---------------- | ------------------------------------------------------------------------------- | -------- | ------------------------- |
| **_amount_** | string \| number | number of shards to spawn | no | `ClientShard#totalShards` |
| **_delay_** | number | delay for spawning each shard ( `in ms` ) | no | 5500 |
| **_timeout_** | number | The amount in milliseconds to wait until the `Bot` has become ready ( `in ms` ) | no | 30000 |

## Basic Setup

in `index.js`

```js
const { ClientShard } = require("aoi.js");

const sharder = new ClientShard("./bot.js",{
token : "DISCORD BOT TOKEN"
});


sharder.startProcess();
```

in `bot.js`

```js
const { Bot } = require("aoi.js");
const bot = new Bot({
token: "DISCORD BOT TOKEN",
prefix: "DISCORD BOT PREFIX",
intents: ["guilds", "guildMessages"],
});

bot.onMessage();

bot.command({
name: "ping",
code: `
Pong!
WS -> $ping ms
ShardId -> $shardId
ShardPing -> $shardPing[$shardId]
`,
});
```

### NOTE
the ***`new index.js`*** is for ClientShard and ***`bot.js is old index.js`***
32 changes: 0 additions & 32 deletions src/other/sharding.md

This file was deleted.