How to get the client Object in the launchfile?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?How do I redirect to another webpage?How to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?

Source of the Wildfire?

Uh oh, the propeller fell off

Alias for root of a polynomial

How to cope with regret and shame about not fully utilizing opportunities during PhD?

Wireless headphones interfere with Wi-Fi signal on laptop

Why weren't the bells paid heed to in S8E5?

Promotion comes with unexpected 24/7/365 on-call

Can I say: "When was your train leaving?" if the train leaves in the future?

Is this a group? If so, what group is it?

Help understanding this line - usage of くれる

How can a layman easily get the consensus view of what academia *thinks* about a subject?

The meaning of the Middle English word “king”

Holding rent money for my friend which amounts to over $10k?

Is it safe to use two single-pole breakers for a 240v circuit?

How to describe a building set which is like LEGO without using the "LEGO" word?

Was the dragon prowess intentionally downplayed in S08E04?

Can a tourist shoot a gun for recreational purpose in the USA?

Mark command as obsolete

A case where Bishop for knight isn't a good trade

Why does lemon juice reduce the "fish" odor of sea food — specifically fish?

Do Grothendieck universes matter for an algebraic geometer?

Were any of the books mentioned in this scene from the movie Hackers real?

Motorola 6845 and bitwise graphics

Can multiple outlets be directly attached to a single breaker?



How to get the client Object in the launchfile?


How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?How do I redirect to another webpage?How to check whether a string contains a substring in JavaScript?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have a Discord Bot which needs sharding now. I created a file named "botlaunch.js", which I start from the console (pm2 start botlaunch.js). In this file is all stuff you need for sharding.



Here is how my botlaunch.js looks like:



const Discord = require('discord.js');
const settings = require('./settings.json');
const chalk = require('chalk');

const shardingManager = new Discord.ShardingManager('./lenoxbot.js',

token: settings.token
);


shardingManager.spawn('auto', 500).then(() =>
console.log(chalk.green(`[ShardManager] Started $shardingManager.totalShards shards`));
).catch(error =>
console.log(error);
);


I need to access the client object after this code. I tried it with the following function but this doesn't work either. No errors or something like this, it only returns undefined for everything I request, doesn't matter what:



function exec(script) 
let requestId = 0;
const currentRequestId = requestId++;

process.send( cmd: 'exec', script: script, reqId: currentRequestId );

const promiseExec = new Promise(resolve =>
_promiseQueue[currentRequestId] = resolve;
);
const promiseTimer = new Promise((resolve, reject) =>
setTimeout(() =>
reject('Promise timed out before completion @ LenoxBotLauncher/exec');
, 60 * 1000);
_promiseQueue.delete(currentRequestId);
);

return Promise.race([promiseExec, promiseTimer]);



Do you have any solutions on how I can use the client under the code of my botlaunch.js?










share|improve this question






















  • What are you needing / trying to do with the client?

    – PLASMA chicken
    Mar 24 at 15:56











  • I need everything. All methods and properties @PLASMAchicken . I need the client for my website/dashboard

    – Gilles Heinesch
    Mar 24 at 16:00

















1















I have a Discord Bot which needs sharding now. I created a file named "botlaunch.js", which I start from the console (pm2 start botlaunch.js). In this file is all stuff you need for sharding.



Here is how my botlaunch.js looks like:



const Discord = require('discord.js');
const settings = require('./settings.json');
const chalk = require('chalk');

const shardingManager = new Discord.ShardingManager('./lenoxbot.js',

token: settings.token
);


shardingManager.spawn('auto', 500).then(() =>
console.log(chalk.green(`[ShardManager] Started $shardingManager.totalShards shards`));
).catch(error =>
console.log(error);
);


I need to access the client object after this code. I tried it with the following function but this doesn't work either. No errors or something like this, it only returns undefined for everything I request, doesn't matter what:



function exec(script) 
let requestId = 0;
const currentRequestId = requestId++;

process.send( cmd: 'exec', script: script, reqId: currentRequestId );

const promiseExec = new Promise(resolve =>
_promiseQueue[currentRequestId] = resolve;
);
const promiseTimer = new Promise((resolve, reject) =>
setTimeout(() =>
reject('Promise timed out before completion @ LenoxBotLauncher/exec');
, 60 * 1000);
_promiseQueue.delete(currentRequestId);
);

return Promise.race([promiseExec, promiseTimer]);



Do you have any solutions on how I can use the client under the code of my botlaunch.js?










share|improve this question






















  • What are you needing / trying to do with the client?

    – PLASMA chicken
    Mar 24 at 15:56











  • I need everything. All methods and properties @PLASMAchicken . I need the client for my website/dashboard

    – Gilles Heinesch
    Mar 24 at 16:00













1












1








1


0






I have a Discord Bot which needs sharding now. I created a file named "botlaunch.js", which I start from the console (pm2 start botlaunch.js). In this file is all stuff you need for sharding.



Here is how my botlaunch.js looks like:



const Discord = require('discord.js');
const settings = require('./settings.json');
const chalk = require('chalk');

const shardingManager = new Discord.ShardingManager('./lenoxbot.js',

token: settings.token
);


shardingManager.spawn('auto', 500).then(() =>
console.log(chalk.green(`[ShardManager] Started $shardingManager.totalShards shards`));
).catch(error =>
console.log(error);
);


I need to access the client object after this code. I tried it with the following function but this doesn't work either. No errors or something like this, it only returns undefined for everything I request, doesn't matter what:



function exec(script) 
let requestId = 0;
const currentRequestId = requestId++;

process.send( cmd: 'exec', script: script, reqId: currentRequestId );

const promiseExec = new Promise(resolve =>
_promiseQueue[currentRequestId] = resolve;
);
const promiseTimer = new Promise((resolve, reject) =>
setTimeout(() =>
reject('Promise timed out before completion @ LenoxBotLauncher/exec');
, 60 * 1000);
_promiseQueue.delete(currentRequestId);
);

return Promise.race([promiseExec, promiseTimer]);



Do you have any solutions on how I can use the client under the code of my botlaunch.js?










share|improve this question














I have a Discord Bot which needs sharding now. I created a file named "botlaunch.js", which I start from the console (pm2 start botlaunch.js). In this file is all stuff you need for sharding.



Here is how my botlaunch.js looks like:



const Discord = require('discord.js');
const settings = require('./settings.json');
const chalk = require('chalk');

const shardingManager = new Discord.ShardingManager('./lenoxbot.js',

token: settings.token
);


shardingManager.spawn('auto', 500).then(() =>
console.log(chalk.green(`[ShardManager] Started $shardingManager.totalShards shards`));
).catch(error =>
console.log(error);
);


I need to access the client object after this code. I tried it with the following function but this doesn't work either. No errors or something like this, it only returns undefined for everything I request, doesn't matter what:



function exec(script) 
let requestId = 0;
const currentRequestId = requestId++;

process.send( cmd: 'exec', script: script, reqId: currentRequestId );

const promiseExec = new Promise(resolve =>
_promiseQueue[currentRequestId] = resolve;
);
const promiseTimer = new Promise((resolve, reject) =>
setTimeout(() =>
reject('Promise timed out before completion @ LenoxBotLauncher/exec');
, 60 * 1000);
_promiseQueue.delete(currentRequestId);
);

return Promise.race([promiseExec, promiseTimer]);



Do you have any solutions on how I can use the client under the code of my botlaunch.js?







javascript node.js bots discord discord.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 14:27









Gilles HeineschGilles Heinesch

1,3921823




1,3921823












  • What are you needing / trying to do with the client?

    – PLASMA chicken
    Mar 24 at 15:56











  • I need everything. All methods and properties @PLASMAchicken . I need the client for my website/dashboard

    – Gilles Heinesch
    Mar 24 at 16:00

















  • What are you needing / trying to do with the client?

    – PLASMA chicken
    Mar 24 at 15:56











  • I need everything. All methods and properties @PLASMAchicken . I need the client for my website/dashboard

    – Gilles Heinesch
    Mar 24 at 16:00
















What are you needing / trying to do with the client?

– PLASMA chicken
Mar 24 at 15:56





What are you needing / trying to do with the client?

– PLASMA chicken
Mar 24 at 15:56













I need everything. All methods and properties @PLASMAchicken . I need the client for my website/dashboard

– Gilles Heinesch
Mar 24 at 16:00





I need everything. All methods and properties @PLASMAchicken . I need the client for my website/dashboard

– Gilles Heinesch
Mar 24 at 16:00












1 Answer
1






active

oldest

votes


















1














You could use ShardingManager#broadcastEval() if you want to obviously eval something, if you need some properties use ShardingManager#fetchClientValues() like:



shardingManager.fetchClientValues('guilds.size')
.then(results =>
console.log(`$results.reduce((prev, guildCount) => prev + guildCount, 0) total guilds`);
)
.catch(console.error);


If you want to broadcastEval/fetchClientValues from inside the Bot you can use client.shard.fetchClientValues()/client.shard.broadcastEval()



There is also a nice guide about it here: https://discordjs.guide/sharding/#broadcasteval




Another way would be to use 2 Clients instead of the ShardingManager like:



const client1 = new Discord.Client( shardId: 0, shardCount: 2);
const client2 = new Discord.Client( shardId: 1, shardCount: 2);



This would mean that the bot will run in 1 process only and this might cause performance issues.







share|improve this answer

























  • Yes I know this, but broadcastEval executes a script on all shards which I don't want because this isn't very performance friendly

    – Gilles Heinesch
    Mar 24 at 16:35












  • fetchClientValues() would be the other options, otherwise I added another way, but it isn't really gonna be performace friendly either.

    – PLASMA chicken
    Mar 24 at 16:49












  • The problem is that you can just get properties with fetchClientValues(), I want to use methods too.

    – Gilles Heinesch
    Mar 24 at 16:53












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55314725%2fhow-to-get-the-client-object-in-the-launchfile%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You could use ShardingManager#broadcastEval() if you want to obviously eval something, if you need some properties use ShardingManager#fetchClientValues() like:



shardingManager.fetchClientValues('guilds.size')
.then(results =>
console.log(`$results.reduce((prev, guildCount) => prev + guildCount, 0) total guilds`);
)
.catch(console.error);


If you want to broadcastEval/fetchClientValues from inside the Bot you can use client.shard.fetchClientValues()/client.shard.broadcastEval()



There is also a nice guide about it here: https://discordjs.guide/sharding/#broadcasteval




Another way would be to use 2 Clients instead of the ShardingManager like:



const client1 = new Discord.Client( shardId: 0, shardCount: 2);
const client2 = new Discord.Client( shardId: 1, shardCount: 2);



This would mean that the bot will run in 1 process only and this might cause performance issues.







share|improve this answer

























  • Yes I know this, but broadcastEval executes a script on all shards which I don't want because this isn't very performance friendly

    – Gilles Heinesch
    Mar 24 at 16:35












  • fetchClientValues() would be the other options, otherwise I added another way, but it isn't really gonna be performace friendly either.

    – PLASMA chicken
    Mar 24 at 16:49












  • The problem is that you can just get properties with fetchClientValues(), I want to use methods too.

    – Gilles Heinesch
    Mar 24 at 16:53
















1














You could use ShardingManager#broadcastEval() if you want to obviously eval something, if you need some properties use ShardingManager#fetchClientValues() like:



shardingManager.fetchClientValues('guilds.size')
.then(results =>
console.log(`$results.reduce((prev, guildCount) => prev + guildCount, 0) total guilds`);
)
.catch(console.error);


If you want to broadcastEval/fetchClientValues from inside the Bot you can use client.shard.fetchClientValues()/client.shard.broadcastEval()



There is also a nice guide about it here: https://discordjs.guide/sharding/#broadcasteval




Another way would be to use 2 Clients instead of the ShardingManager like:



const client1 = new Discord.Client( shardId: 0, shardCount: 2);
const client2 = new Discord.Client( shardId: 1, shardCount: 2);



This would mean that the bot will run in 1 process only and this might cause performance issues.







share|improve this answer

























  • Yes I know this, but broadcastEval executes a script on all shards which I don't want because this isn't very performance friendly

    – Gilles Heinesch
    Mar 24 at 16:35












  • fetchClientValues() would be the other options, otherwise I added another way, but it isn't really gonna be performace friendly either.

    – PLASMA chicken
    Mar 24 at 16:49












  • The problem is that you can just get properties with fetchClientValues(), I want to use methods too.

    – Gilles Heinesch
    Mar 24 at 16:53














1












1








1







You could use ShardingManager#broadcastEval() if you want to obviously eval something, if you need some properties use ShardingManager#fetchClientValues() like:



shardingManager.fetchClientValues('guilds.size')
.then(results =>
console.log(`$results.reduce((prev, guildCount) => prev + guildCount, 0) total guilds`);
)
.catch(console.error);


If you want to broadcastEval/fetchClientValues from inside the Bot you can use client.shard.fetchClientValues()/client.shard.broadcastEval()



There is also a nice guide about it here: https://discordjs.guide/sharding/#broadcasteval




Another way would be to use 2 Clients instead of the ShardingManager like:



const client1 = new Discord.Client( shardId: 0, shardCount: 2);
const client2 = new Discord.Client( shardId: 1, shardCount: 2);



This would mean that the bot will run in 1 process only and this might cause performance issues.







share|improve this answer















You could use ShardingManager#broadcastEval() if you want to obviously eval something, if you need some properties use ShardingManager#fetchClientValues() like:



shardingManager.fetchClientValues('guilds.size')
.then(results =>
console.log(`$results.reduce((prev, guildCount) => prev + guildCount, 0) total guilds`);
)
.catch(console.error);


If you want to broadcastEval/fetchClientValues from inside the Bot you can use client.shard.fetchClientValues()/client.shard.broadcastEval()



There is also a nice guide about it here: https://discordjs.guide/sharding/#broadcasteval




Another way would be to use 2 Clients instead of the ShardingManager like:



const client1 = new Discord.Client( shardId: 0, shardCount: 2);
const client2 = new Discord.Client( shardId: 1, shardCount: 2);



This would mean that the bot will run in 1 process only and this might cause performance issues.








share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 16:48

























answered Mar 24 at 16:26









PLASMA chickenPLASMA chicken

1,3042818




1,3042818












  • Yes I know this, but broadcastEval executes a script on all shards which I don't want because this isn't very performance friendly

    – Gilles Heinesch
    Mar 24 at 16:35












  • fetchClientValues() would be the other options, otherwise I added another way, but it isn't really gonna be performace friendly either.

    – PLASMA chicken
    Mar 24 at 16:49












  • The problem is that you can just get properties with fetchClientValues(), I want to use methods too.

    – Gilles Heinesch
    Mar 24 at 16:53


















  • Yes I know this, but broadcastEval executes a script on all shards which I don't want because this isn't very performance friendly

    – Gilles Heinesch
    Mar 24 at 16:35












  • fetchClientValues() would be the other options, otherwise I added another way, but it isn't really gonna be performace friendly either.

    – PLASMA chicken
    Mar 24 at 16:49












  • The problem is that you can just get properties with fetchClientValues(), I want to use methods too.

    – Gilles Heinesch
    Mar 24 at 16:53

















Yes I know this, but broadcastEval executes a script on all shards which I don't want because this isn't very performance friendly

– Gilles Heinesch
Mar 24 at 16:35






Yes I know this, but broadcastEval executes a script on all shards which I don't want because this isn't very performance friendly

– Gilles Heinesch
Mar 24 at 16:35














fetchClientValues() would be the other options, otherwise I added another way, but it isn't really gonna be performace friendly either.

– PLASMA chicken
Mar 24 at 16:49






fetchClientValues() would be the other options, otherwise I added another way, but it isn't really gonna be performace friendly either.

– PLASMA chicken
Mar 24 at 16:49














The problem is that you can just get properties with fetchClientValues(), I want to use methods too.

– Gilles Heinesch
Mar 24 at 16:53






The problem is that you can just get properties with fetchClientValues(), I want to use methods too.

– Gilles Heinesch
Mar 24 at 16:53




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55314725%2fhow-to-get-the-client-object-in-the-launchfile%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript