Исправлен подсчёт пользователей

This commit is contained in:
Jonny_Bro (Nikita) 2023-03-30 15:52:58 +05:00
parent 7aaaa914f5
commit 77fbca032c
5 changed files with 29 additions and 15 deletions

View file

@ -54,7 +54,7 @@ class Leaderboard extends BaseCommand {
const membersLeaderboard = [],
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
await client.functions.asyncForEach(membersData, async member => {
client.functions.asyncForEach(membersData, member => {
membersLeaderboard.push({
id: member.id,
money: member.money + member.bankSold,
@ -97,7 +97,7 @@ class Leaderboard extends BaseCommand {
const membersLeaderboard = [],
membersData = await client.membersData.find({ guildID: interaction.guildId }).lean();
await client.functions.asyncForEach(membersData, async member => {
client.functions.asyncForEach(membersData, async member => {
membersLeaderboard.push({
id: member.id,
level: member.level,
@ -151,7 +151,7 @@ class Leaderboard extends BaseCommand {
const usersLeaderboard = [],
usersData = await client.usersData.find({ rep: { $gt: 0 } }).lean();
await client.functions.asyncForEach(usersData, async user => {
client.functions.asyncForEach(usersData, async user => {
usersLeaderboard.push({
id: user.id,
rep: user.rep,

View file

@ -31,9 +31,13 @@ class Stats extends BaseCommand {
* @param {Object} data
*/
async execute(client, interaction, data) {
const hiddenGuild = await client.guilds.fetch("568120814776614924");
const users = client.users.cache.size - hiddenGuild.memberCount;
const hiddenGuildMembersCount = client.guilds.cache.get("568120814776614924").memberCount;
const servers = client.guilds.cache.size - 1;
let users = 0;
client.guilds.cache.forEach(g => {
users += g.memberCount;
});
users = users - hiddenGuildMembersCount;
const statsEmbed = new EmbedBuilder()
.setColor(client.config.embed.color)

View file

@ -14,13 +14,19 @@ class Ready extends BaseEvent {
*/
async execute(client) {
const commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()];
let hiddenGuild = await client.guilds.fetch("568120814776614924");
let tUsers = client.users.cache.size - hiddenGuild.memberCount;
let hiddenGuildMembersCount = client.guilds.cache.get("568120814776614924").memberCount;
let tServers = client.guilds.cache.size - 1;
let tUsers = 0;
client.guilds.cache.forEach(g => {
tUsers += g.memberCount;
});
tUsers = tUsers - hiddenGuildMembersCount;
client.logger.log(`Loaded a total of ${commands.length} command(s).`, "ready");
client.logger.log(`${client.user.tag}, ready to serve ${tUsers} users in ${tServers} servers.`, "ready");
client.logger.log(`${client.user.tag}, ready to serve ${tUsers} members in ${tServers} servers.`, "ready");
client.logger.log(`Invite Link: ${client.generateInvite({ scopes: ["bot", "applications.commands"], permissions: [ PermissionsBitField.Flags.Administrator ] })}`, "ready");
console.timeEnd("botReady");
const birthdays = require("../helpers/birthdays");
birthdays.init(client);
@ -46,18 +52,21 @@ class Ready extends BaseEvent {
let i = 0;
setInterval(async function () {
hiddenGuild = await client.guilds.fetch("568120814776614924");
tUsers = client.users.cache.size - hiddenGuild.memberCount;
hiddenGuildMembersCount = client.guilds.cache.get("568120814776614924").memberCount;
tServers = client.guilds.cache.size - 1;
const toShow = status[i];
tUsers = 0;
client.guilds.cache.forEach(g => {
tUsers += g.memberCount;
});
tUsers = tUsers - hiddenGuildMembersCount;
client.user.setActivity(`${toShow.name} | v${version}`, {
type: toShow.type,
client.user.setActivity(`${status[i].name} | v${version}`, {
type: status[i].type,
});
if (status[i + 1]) i++;
else i = 0;
}, 10000); // Every 10 seconds
}, 30 * 1000); // Every 30 seconds
}
}

View file

@ -14,6 +14,7 @@ const client = new JaBa({
await client.loadEvents("../events");
await client.loadCommands("../commands");
await client.init();
console.time("botReady");
})();
client.on("disconnect", () => client.logger.log("Bot is disconnecting...", "warn"))

View file

@ -11,7 +11,7 @@ const checks = [
() => {
console.log("\n\nEnvironnement");
return new Promise(res => {
if (parseInt(process.version.split(".")[0].split("v")[1]) >= 18) {
if (parseInt(process.versions.node.split(".")[0]) >= 18) {
success("node.js version equal or higher than v18");
} else {
error("node.js version should be equal or higher than v18");