question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Add a command to get server stats

See original GitHub issue

When a user types !stats, a message should appear with the following data:

  • total users
  • total messages
  • total reactions

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
}

Error handling

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
garretcharpcommented, Jun 9, 2020

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.

1reaction
eddiejaoudecommented, Jun 9, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setup - ServerStats Bot
The first thing you have to do is add the bot to your server, use the button under this text to add the...
Read more >
How to Add Server Stats on Discord (2022) - YouTube
In this video, i will show you how to install and setup the StatServerBot for Discord. This handly little tool allows you display...
Read more >
How To Add And Setup Server Stats Bot 2022 - YouTube
Server Stats bot is a discord bot that is used to monitor the statistics of your Discord server. It can be used to...
Read more >
How to setup Discord server stats bot 2021 (mobile and pc)
In this video ill show you how to setup server stats bot for your discord server in 2021 so you can have a...
Read more >
How to Display Member Count / ServerStats in Discord
In this video, you will learn how to use Statbot Statdocks to display important server stats in your discord like member count, bot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found