How to properly communicate between shards?

I tried something like this, but it ended up sending hundreds of messages when it should have sent one, or otherwise just crashing out. I can't seem to find a good guide or example on how to set up a way for one shard to communicate something to all shards.
// Index.ts
manager.spawn()
    .then(shards => {
        shards.forEach(shard => {
            shard.on('message', message => {
                manager.broadcast(message);
            });
        });
    })
    .catch(console.error);
// Bot.ts
process.on('message', (message: string) => {
    let data;
    try {
        data = JSON.parse(message);
    } catch {
        return;
        // Ignore
    }

    console.log(data.message);
});

/// On an event:
process.send(JSON.stringify({ message: 'Hello World!'}));
Was this page helpful?