diff --git a/src/SUMMARY.md b/src/SUMMARY.md index a462a59c..62c9efd9 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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") *** @@ -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) diff --git a/src/advanced-guides/sharding.md b/src/advanced-guides/sharding.md new file mode 100644 index 00000000..34b0f6a5 --- /dev/null +++ b/src/advanced-guides/sharding.md @@ -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 + + + + + + + + + + + + + + + + + + +
Typestring
DescriptionPath to bot file
Requiredyes
DefaultN/A
+ +### 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`*** \ No newline at end of file diff --git a/src/other/sharding.md b/src/other/sharding.md deleted file mode 100644 index 0ac7045b..00000000 --- a/src/other/sharding.md +++ /dev/null @@ -1,32 +0,0 @@ -# Sharding - -{% hint style="danger" %} -Sharding is only necessary for bots in 2,000+ Guilds -{% endhint %} - -#### How to shard - -```javascript -const bot = new Aoijs.bot({ - sharding: true, - shardAmount: 2, - token: "token", - prefix: "prefix" -}) -``` - -#### Finding current guild's shard ID - -```javascript -bot.command({ - name: "shardID", - code: `Guilds Shard: $shardID` -}) -``` - -{% hint style="danger" %} -Sharding can lead to high ping/response time and depending your host, can use a lot of memory and disk space -{% endhint %} - - -