When a user types !stats, a message should appear with the following data:
Proposed solution for total users
// inside case 'stats' on commands.ts
const memberCount = getServerMemberCount(message.client);
export function getServerMemberCount(client: Client) {
const guildKey = process.env.DISCORD_SERVER_ID
if (!guildKey) {
console.error(`Missing env. variable DISCORD_SERVER_ID. Please configure that value.`)
return 0
}
const guild = client.guilds.cache.get(guildKey)
if (!guild) {
console.error(`The guild with the configured DISCORD_SERVER_ID env. variable doesn't exist`)
return 0
}
return guild.memberCount
}
In case of an error getting the member count for the guild, we can return 0 or null and then don't show that field on the final message. This is something I'd like your opinions on.
I'd also like to hear your feedback @eddiejaoude, on a better way to get the server's guild and add a default maybe. I proposed a new env. variable in order for the bot to work for various discord servers. It just has to be configured first.
Here is the card for this feature.
Oh interesting, does discord have all that data? When I started reading it, I thought we would have to manage it in a DB
Yeah, I found the memberCount so we can use it for total users. But I'm not sure they have all the data we want, maybe we need a DB.
For example, I've only found a way of getting the messages using their API of a channel like this:
// Get messages
channel.messages.fetch({ limit: 10 })
.then(messages => console.log(`Received ${messages.size} messages`))
.catch(console.error);
So we could loop through all the text channels in the server, and sum all the messages. But their limit option only goes up to 100, so I don't know how efficient this is if our total messages is like 2000 馃槄
I think we should save the data, there will be functions running for each of those triggers anyway, so we can just increment the counter at the same time
The total reactions stat is still in progress? @garretcharp I think I remember you mentioned you were working on a piece of code to get the total reactions or did you make a PR already?
I think it is waiting on me to store data in the DB - I will finish the logger tomorrow that also outputs to the bot channel, then I will get back to the saving of data in the DB, which will open lots of doors
Yeah I do not think it is possible to get the total amount of reactions without a database. Other than looping through every message on the server which really should not be done.
Stale issue message
I am going to close this for now. I think what we have is good enough for now
