pass variables into <ShardClientUtil>.broadcastEval()

I've got the following code:
var commandName = `foo`;

await client.shard.broadcastEval(async (c) => {

delete require.cache[require.resolve(`../${commandName}.js`)];
});
var commandName = `foo`;

await client.shard.broadcastEval(async (c) => {

delete require.cache[require.resolve(`../${commandName}.js`)];
});
how would i modify the function to include var commandName inside of broadcastEval() ?
3 Replies
d.js toolkit
d.js toolkit4mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
space
space4mo ago
By passing a context option as second parameter with your variable and then referencing that. https://discordjs.dev/docs/packages/discord.js/14.15.3/ShardClientUtil:Class#broadcastEval (overload 3)
d.js docs
d.js docs4mo ago
:guide: Sharding: Additional information - Eval arguments 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. read more
Want results from more Discord servers?
Add your server