diff --git a/guide/sharding/additional-information.md b/guide/sharding/additional-information.md index 4032b35e2..203939237 100644 --- a/guide/sharding/additional-information.md +++ b/guide/sharding/additional-information.md @@ -77,14 +77,23 @@ 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. @@ -96,3 +105,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