From ead101ae8856af1ecf7c212f52aca3aaa5be9f44 Mon Sep 17 00:00:00 2001 From: heavylightdecomp Date: Wed, 21 May 2025 18:19:18 +1000 Subject: [PATCH 1/4] clarify eval arguments section --- guide/sharding/additional-information.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/guide/sharding/additional-information.md b/guide/sharding/additional-information.md index 4032b35e2..4397e34af 100644 --- a/guide/sharding/additional-information.md +++ b/guide/sharding/additional-information.md @@ -77,14 +77,22 @@ You can access them later as usual via `process.argv`, which contains an array o ## Eval arguments -There may come the point where you will want to pass arguments from the outer scope into a `.broadcastEval()` call. +There may come the point where you will want to pass arguments from the outer scope into a `.broadcastEval()` call. The `context` property is useful for this purpose: ```js -function funcName(c, { arg }) { - // ... +function funcName(client, context) { + console.log(context.arg); } -client.shard.broadcastEval(funcName, { context: { arg: 'arg' } }); +//Eval on all shards +client.shard.broadcastEval(funcName, { + context: { arg: 'arg' } +}); +//Eval on a specific shard +client.shard.broadcastEval(funcName, { + shard: 0, + context: { arg: 'some stuff' } +}); ``` The `BroadcastEvalOptions` typedef was introduced in discord.js v13 as the second parameter in `.broadcastEval()`. It accepts two properties: `shard` and `context`. The `context` property will be sent as the second argument to your function. From 136a35cf7880299d4dc0e7b3e00acf39c3074656 Mon Sep 17 00:00:00 2001 From: heavylightdecomp Date: Wed, 21 May 2025 18:36:57 +1000 Subject: [PATCH 2/4] linting checks --- guide/sharding/additional-information.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/guide/sharding/additional-information.md b/guide/sharding/additional-information.md index 4397e34af..01930022d 100644 --- a/guide/sharding/additional-information.md +++ b/guide/sharding/additional-information.md @@ -84,11 +84,11 @@ function funcName(client, context) { console.log(context.arg); } -//Eval on all shards -client.shard.broadcastEval(funcName, { - context: { arg: 'arg' } +// Eval on all shards +client.shard.broadcastEval(funcName, { + context: { arg: 'arg' } }); -//Eval on a specific shard +// Eval on a specific shard client.shard.broadcastEval(funcName, { shard: 0, context: { arg: 'some stuff' } @@ -104,3 +104,6 @@ The function will receive the arguments as an object as the second parameter. The `context` option only accepts properties which are JSON-serializable. This means you cannot pass complex data types in the context directly. For example, if you sent a `User` instance, the function would receive the raw data object. ::: +::: tip +The [next section](/sharding/extended.md) will go into more detail about various use cases of `.broadcastEval()` +::: \ No newline at end of file From bc05a4bb5b39a084217be0c5ea0ef3760dc34a06 Mon Sep 17 00:00:00 2001 From: heavylightdecomp Date: Thu, 22 May 2025 14:31:20 +1000 Subject: [PATCH 3/4] added newline --- guide/sharding/additional-information.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guide/sharding/additional-information.md b/guide/sharding/additional-information.md index 01930022d..ab74b0806 100644 --- a/guide/sharding/additional-information.md +++ b/guide/sharding/additional-information.md @@ -104,6 +104,7 @@ The function will receive the arguments as an object as the second parameter. The `context` option only accepts properties which are JSON-serializable. This means you cannot pass complex data types in the context directly. For example, if you sent a `User` instance, the function would receive the raw data object. ::: + ::: tip The [next section](/sharding/extended.md) will go into more detail about various use cases of `.broadcastEval()` ::: \ No newline at end of file From 35c22bc1b4a1ff9640c29ad390b4bcafc69eab09 Mon Sep 17 00:00:00 2001 From: heavylightdecomp <111647750+heavylightdecomp@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:10:58 +1000 Subject: [PATCH 4/4] Update guide/sharding/additional-information.md Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- guide/sharding/additional-information.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guide/sharding/additional-information.md b/guide/sharding/additional-information.md index ab74b0806..203939237 100644 --- a/guide/sharding/additional-information.md +++ b/guide/sharding/additional-information.md @@ -88,6 +88,7 @@ function funcName(client, context) { client.shard.broadcastEval(funcName, { context: { arg: 'arg' } }); + // Eval on a specific shard client.shard.broadcastEval(funcName, { shard: 0,