sharding related fixes

This commit is contained in:
Erik 2022-05-11 15:57:36 +03:00
parent 4e2ae7344c
commit 6f74e9af0a
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 7 additions and 3 deletions

View File

@ -38,7 +38,7 @@ class BaseClient extends EventEmitter {
process.exit(); // Prevent a boot loop when shards die due to an error in the client process.exit(); // Prevent a boot loop when shards die due to an error in the client
}); });
this.logger.status('Shards spawned'); this.logger.status(`Shards spawned, spawned ${this.shardingManager.shards.size} shards`);
const API = this._options.api.load ? await import('/Documents/My programs/GBot/api/index.js') const API = this._options.api.load ? await import('/Documents/My programs/GBot/api/index.js')
.catch(() => this.logger.warn(`Error importing API files, continuing without`)) : null; .catch(() => this.logger.warn(`Error importing API files, continuing without`)) : null;

View File

@ -158,11 +158,15 @@ class DiscordClient extends Client {
async _setActivity() { async _setActivity() {
const activities = { const activities = {
0: async () => { 0: async () => {
const guildCount = (await this.shard.broadcastEval((client) => client.guilds.cache.size)).reduce((p, v) => p+v, 0); const result = await this.shard.broadcastEval((client) => client.guilds.cache.size).catch(() => null);
if (!result) return;
const guildCount = result.reduce((p, v) => p+v, 0);
this.user.setActivity(`${guildCount} servers`, { type: 'WATCHING' }); this.user.setActivity(`${guildCount} servers`, { type: 'WATCHING' });
}, },
1: async () => { 1: async () => {
const userCount = (await this.shard.broadcastEval((client) => client.users.cache.size)).reduce((p, v) => p+v, 0); const result = await this.shard.broadcastEval((client) => client.users.cache.size).catch(() => null);
if (!result) return;
const userCount = result.reduce((p, v) => p+v, 0);
this.user.setActivity(`to ${userCount} users`, { type: 'LISTENING' }); this.user.setActivity(`to ${userCount} users`, { type: 'LISTENING' });
}, },
2: async () => { 2: async () => {