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);
}
});
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();
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
3 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
monbrey
monbrey2mo ago
You don't share them - you make note of which shard is handling them, and broadcast functions that need to make use of those channels to it
Lawa
LawaOP2mo ago
alright thank you
Want results from more Discord servers?
Add your server