Sheepolution
Sheepolution
DIAdiscord.js - Imagine an app
Created by Sheepolution on 11/27/2024 in #djs-questions
How to properly communicate between shards?
I changed it to the following, and it looks like this works? No errors so far.
manager.spawn()
.then(shards => {
shards.forEach(shard => {
shard.on('message', message => {
if (typeof message !== 'string') {
return;
}

if (message.startsWith('__EVENT:')) {
try {
manager.broadcast(message);
} catch {
// Ignore
}
}
});
});
})
.catch(console.error);
manager.spawn()
.then(shards => {
shards.forEach(shard => {
shard.on('message', message => {
if (typeof message !== 'string') {
return;
}

if (message.startsWith('__EVENT:')) {
try {
manager.broadcast(message);
} catch {
// Ignore
}
}
});
});
})
.catch(console.error);
// Bot.ts
process.on('message', (message: string) => {
if (typeof message !== 'string') {
return;
}

if (!message.startsWith('__EVENT:')) {
return;
}

const parts = message.split(':');
const command = parts[1];

if (command == 'hello') {
console.log('Hello World!');
}
});

/// On an event
process.send('__EVENT:hello');
// Bot.ts
process.on('message', (message: string) => {
if (typeof message !== 'string') {
return;
}

if (!message.startsWith('__EVENT:')) {
return;
}

const parts = message.split(':');
const command = parts[1];

if (command == 'hello') {
console.log('Hello World!');
}
});

/// On an event
process.send('__EVENT:hello');
4 replies
DIAdiscord.js - Imagine an app
Created by Sheepolution on 11/27/2024 in #djs-questions
How to properly communicate between shards?
Nope
4 replies
DIAdiscord.js - Imagine an app
Created by Sheepolution on 12/4/2022 in #djs-questions
How to make sharding and caching work together?
I suppose I should do that yeah. Currently my caching is storing a whole class instance. Hmmmm
10 replies
DIAdiscord.js - Imagine an app
Created by Sheepolution on 12/4/2022 in #djs-questions
How to make sharding and caching work together?
Let's say my database keeps track of players. In a server they can play a game (using my bot) and the data of this game is added to the database. It keeps a counter of how many games you played. 1. You check your stats in DMs. It says 5 games, and this is now cached. 2. You play three games in a server. The server is on a different shard. It updates your total games to 8. 3. You check your stats in DMs again. It still says 5 games, because this data was cached.
10 replies
DIAdiscord.js - Imagine an app
Created by Sheepolution on 12/4/2022 in #djs-questions
How to make sharding and caching work together?
I meant a configuration in my database. That the caching between shards results in data different than what's in the database. I don't want to change the shard they're on, and I'm using shard 0 because of the very reason that its used in dms
10 replies