Shard Variables

bot.once(Events.ShardReady, async () => {
  imgchannel = bot.channels.cache.get(process.env.IMAGE_CHANNEL);
  vidchannel = bot.channels.cache.get(process.env.VIDEO_CHANNEL);
  module.exports.imgchannel = imgchannel;
  module.exports.vidchannel = vidchannel;
  shardId = bot.shard.ids[0];
  bot.user.setActivity({
    name: `/help | Shard ${bot.shard.ids[0]}`,
    type: ActivityType.Watching,
    shardId: bot.shard.ids[0],
  });
  if (shardId === 0) {
    //Initialize database
    // initializeDb()
    //   .then(() => {
    //     console.log("Database initialized successfully.");
    //   })
    //   .catch((err) => {
    //     console.error("Error initializing database:", err);
    //   });
    console.log("Started Source");
    client.login(process.env.oth_TOKEN);
  }
});


i have these variables vidchannel, imgchannel which can only be accessed by whatever shard access the server that can read the cache of these channels (if that makes sense). Users on other shards can't access these channels. How do i share these variables accross every shard while fetching them from the shard that access the server in which these channels are.

require("dotenv").config();
const { ShardingManager } = require('discord.js');

const manager = new ShardingManager('./xmain.js', { 
  token: process.env.BOT_TOKEN,
  totalShards: 1 // Limit to a single shard
});

manager.on('shardCreate', shard => {
    console.log(`Launched shard ${shard.id}`);
});

manager.spawn();

I currently limited the shards count to 1 until i can figure out a solution
Was this page helpful?