Search code examples
javascriptshardingdiscord.js

I need to get the the user count of a shard by its ID


I am using Discord v11.4.2

How do I get the user count of a shard by using the shard's ID? Currently I have this code:

client.shard.broadcastEval('this.users.size').then(i => console.log(i))

And it logs both user sizes but I need the user size of shard ID 1. How can I do this?


Solution

  • You can check the shard ID with .broadcastEval('this.shard.id'), so try using

    client.shard.broadcastEval('this.shard.id == 1 ? this.users.size : false')
      .then(arr => {
        for (let result of arr)
          if (result) console.log(result);
      });
    

    Disclaimer: I'm not very practical with shards, so this could not be the best solution.