简体   繁体   English

如何使用分片管理器从ShardClientUtil访问shardArgs?

[英]How can I access the shardArgs from the ShardClientUtil, using the sharding manager?

I'm setting up a Bot using Discord.JS and want to pass the shardArgs option from the ShardingManager to the ShardClient . 我正在使用Discord.JS设置Bot,并希望将shardArgs选项从ShardingManager传递到ShardClient How do I access the option ( shardArgs ) from the ShardClientUtil ? 如何从ShardClientUtil访问选项( shardArgs )?

// ShardManager.js
const Discord = require('discord.js');

const Manager = new Discord.ShardingManager('./Main.js', {
     shardArgs: ["shard args to be passed through"]
});

Manager.spawn(1);

I've tried using .fetchClientValues() : 我尝试使用.fetchClientValues()

// Main.js
const Discord = require('discord.js');
const client = new Discord.Client();

client.shard.fetchClientValues('manager.shardArgs') 
   .then(results => {
    console.log(results);
   })
   .catch(console.error);

client.login("token");

I've tried many different things, I even checked the object in a debugger, but I was unable to find shardArgs so I'm not sure where I'm supposed to access it from. 我已经尝试了许多不同的方法,甚至在调试器中检查了对象,但是我无法找到shardArgs因此我不确定应该从哪里访问它。

I expect shardArgs to be "shard args to be passed through" , while at the moment I'm getting null . 我希望shardArgs"shard args to be passed through" ,而目前我正在获得null

The shardArgs are actually passed around a bit: shardArgs实际上传递了一下:


You can access your array in your shards via process.argv . 您可以通过process.argv在分片中访问数组。 (No need for IPC) (无需IPC)

Mind that the first entry is the exeuctable (node) and the second is the file being executed (Main.js), the third and up entries are your array's. 请记住,第一个条目是可执行的(节点),第二个条目是正在执行的文件(Main.js),第三个及以上的条目是数组的条目。

As an example logging process.argv in your Main.js file might log: 例如,在Main.js文件中记录process.argv可能会记录:
['usr/bin/node', '/home/bot/Main.js', 'shard args to be passed through']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅使用 NodeJs 的内部 HTTP 模块从 POST 请求访问正文参数? - How can I access the body parameters from a POST request using only the internal HTTP module from NodeJs? 如何使用JavaScript从微软交换服务器访问邮件? - how can i access mail from a microsoft exchange server using javascript? 如何使用服务器域名从本地计算机访问我的nodejs Web服务器? - How can I access my nodejs web server from my local computer using the server domain name? 如何使用REST / JSON / GET / POST从我的节点服务器访问我的couchdb? - How can I access my couchdb from my node server using REST/JSON/GET/POST? 使用 react 中的 express-fileupload 时如何访问文本输入字段 - How can I access the text input fields when using express-fileupload from react 如何从谷歌秘密管理器访问多个秘密? - How to access multiple secrets from google secret manager? 如何在arangodb中使用分片? - How to use Sharding in arangodb? 我可以仅使用JavaScript制作客户端/服务器任务管理器吗? - Can I make a client/server Task Manager using only JavaScript? 如何从NodeJS REST API访问Google API? - How can i access Google APIs from NodeJS REST API? 如何从类外部访问类中的方法 - How can I access methods inside a class from outside of class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM