API Not showing the right player ammount

[
{
"shard_id": 0,
"is_ready": true,
"latency": -1,
"server_count": 8,
"cached_user_count": 3,
"uptime": 6801
}
]
[
{
"shard_id": 0,
"is_ready": true,
"latency": -1,
"server_count": 8,
"cached_user_count": 3,
"uptime": 6801
}
]
So my API is only showing 3 user count but there is way and way more in my main guild so I am really confused as to why my API code
js
app.get('/status', async (req, res) => {
try {
if (!client.isReady()) {
return res.status(503).json({ error: 'Bot is not ready' });
}

const shardStatuses = await client.shard.broadcastEval(async (client) => {
const server_count = client.guilds.cache.size;
const member_counts = await Promise.all(client.guilds.cache.map(guild => guild.memberCount));
const total_member_count = member_counts.reduce((a, b) => a + b, 0);

return {
shard_id: client.shard.ids[0],
is_ready: client.isReady(),
latency: client.ws.ping,
server_count: server_count,
cached_user_count: total_member_count,
uptime: client.uptime,
};
});

res.json(shardStatuses);
} catch (error) {
Logger.error('Error fetching shard status:', error);
res.status(500).json({ error: 'Failed to fetch shard status' });
}
});
js
app.get('/status', async (req, res) => {
try {
if (!client.isReady()) {
return res.status(503).json({ error: 'Bot is not ready' });
}

const shardStatuses = await client.shard.broadcastEval(async (client) => {
const server_count = client.guilds.cache.size;
const member_counts = await Promise.all(client.guilds.cache.map(guild => guild.memberCount));
const total_member_count = member_counts.reduce((a, b) => a + b, 0);

return {
shard_id: client.shard.ids[0],
is_ready: client.isReady(),
latency: client.ws.ping,
server_count: server_count,
cached_user_count: total_member_count,
uptime: client.uptime,
};
});

res.json(shardStatuses);
} catch (error) {
Logger.error('Error fetching shard status:', error);
res.status(500).json({ error: 'Failed to fetch shard status' });
}
});
5 Replies
d.js toolkit
d.js toolkit3mo 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
Syjalo
Syjalo3mo ago
Do you use internal sharding? And why do you use sharding with such a low guilds count?
X_DigitalNinja
X_DigitalNinjaOP3mo ago
I am using sharding and making it for the future so I have it ready to go and I am using i am using shardingmanager
js
import { ShardingManager } from 'discord.js';
import 'dotenv/config'; // Load environment variables
import Logger from './src/utils/logger.js'; // Custom logger utility

// Create a ShardingManager
const manager = new ShardingManager('./src/main.js', {
totalShards: 'auto', // Automatically determine the number of shards based on Discord's recommendation
token: process.env.PRODUCTION_CLIENT_AUTH_TOKEN, // Use your production token
});

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

// Spawn shards
manager.spawn().then(shards => {
Logger.success('All shards spawned successfully!');
}).catch(err => {
Logger.error(`Failed to spawn shards: ${err.message}`);
});

export default manager;
js
import { ShardingManager } from 'discord.js';
import 'dotenv/config'; // Load environment variables
import Logger from './src/utils/logger.js'; // Custom logger utility

// Create a ShardingManager
const manager = new ShardingManager('./src/main.js', {
totalShards: 'auto', // Automatically determine the number of shards based on Discord's recommendation
token: process.env.PRODUCTION_CLIENT_AUTH_TOKEN, // Use your production token
});

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

// Spawn shards
manager.spawn().then(shards => {
Logger.success('All shards spawned successfully!');
}).catch(err => {
Logger.error(`Failed to spawn shards: ${err.message}`);
});

export default manager;
My friend sent me that so I just been using it idk :idk: lol what you recommend For future discord-hybrid-sharding? I know but again for the future if there was a possibility ahh gotcha
Syjalo
Syjalo3mo ago
Even if you reach 2500 guilds, you can shard with the client without any manager until about 5 shards
X_DigitalNinja
X_DigitalNinjaOP3mo ago
Oh ok Thanks guys!
Want results from more Discord servers?
Add your server