[英]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
实际上传递了一下:
Shard
's constructor Shard
的构造函数 Shard#spawn
Shard#spawn
child_process.fork
(which will start the shard's process) child_process.fork
(它将启动分片的过程) 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.