从第二个文件加载数据对象时,该对象为空。有没有办法获取所有文件上的对象子级?
索引.js:
const {ShardingManager} = require('discord.js');
require('dotenv').config();
const chalk = require('chalk');
const storage = require('./Modules/GlobalStorage');
storage.setDataObject('test', 'test_value');
console.log(chalk.yellow(`Shard Manager Data: ${JSON.stringify(storage.listDataObjects())}`));
let shardManager = new ShardingManager('./Shard/index.js', {
totalShards: 2,
token: process.env.CLIENT_TOKEN
});
shardManager.spawn();
shardManager.on('shardCreate', (shard) => {
console.log(chalk.rgb(75,0,130)(`[SHARD] Created Shard (ID: ${shard.id})`));
});
模块/全局存储.js:
let DataObject = {};
exports.listDataObjects = () => {
return DataObject;
};
exports.setDataObject = (key, property) => {
DataObject[key] = property;
if(DataObject[key]) return true;
};
exports.getDataObject = (key) => {
return DataObject[key];
};
分片/索引.js:
const {listDataObjects, getDataObject} = require("../Modules/GlobalStorage");
console.log(chalk.yellow(`Shard Data: ${JSON.stringify(listDataObjects())}`));
我标记discord.js的原因是这是我的discord bot,它是分片的,这是(我相信)问题。
心有法竹
相关分类