Eddiebot: BUG: Stats command total messages broken

Created on 5 Dec 2020  ยท  13Comments  ยท  Source: EddieJaoudeCommunity/EddieBot

The problem:

The stats command has a field for Total Messages and since 06/05/2020 this field has reported total messages as 0
This might be a consequence of EddieBot not having read perms in all channels of the discord server.

Expected behaviour:

expected

Current Behaviour:

Screenshot 2020-12-05 at 12 58 30 PM

Potential fixes:

1- Give eddiebot admin perms(not recommended IMHO)
OR
2- Give eddiebot "Read Message History" access to all the channels
OR
3- Refactor the ^stats command(stats.service.ts) to account for the scenario where EddieBot doesn't have read perms to a channel and tries fetching the channel messages.
https://github.com/EddieJaoudeCommunity/EddieBot/blob/f07f2ed3cf49738d704cbcd010be3a9ff6fbc612/src/commandHandlers/stats.service.ts#L46-L59

bug

Most helpful comment

Oh, thanks for testing.

Can you update your list of options with what has been tried and if it did not work, something like

| Possible solution | Tested | Fixed |
| :--- | :--- | :--- |
| Give eddiebot admin perms(not recommended IMHO) | โœ… | ๐Ÿšซ |
| Give eddiebot "Read Message History" access to all the channels | - | - |
| Refactor the ^stats command(stats.service.ts) to account for the scenario where EddieBot doesn't have read perms to a channel and tries fetching the channel messages. | - | - |

All 13 comments

It's great having you contribute to this project

Feel free to raise an Issue! Welcome to the community :nerd_face:

If you would like to continue contributing to open source and would like to do it with an awesome inclusive community, you should join our Discord chat and our GitHub Organisation - we help and encourage each other to contribute to open source little and often ๐Ÿค“ . Any questions let us know.

Thank you for raising this issue and for all the information you included in it ๐Ÿ‘

Hi @Vyvy-vi ๐Ÿ˜ƒ, sorry but could you provide more details about the third option? I didn't understand how you propose we refactor that function, should it return something else than zero inside the catch clause?

I'm not sure how to make an alteration while keeping it parallel
Is there a way, we could check if the bot can access a channel using channel.permissionsFor(message.guild.me).has('VIEW_CHANNEL') before fetching messages?

@Vyvy-vi yes I think something like that would work.

Something like this:

import { Client, TextChannel, Channel, Permissions } from 'discord.js';
//...
const botUser = this.discordClient.user;
const messagePromises = this.discordClient.channels.cache 
       .filter((ch: Channel) => ch instanceof TextChannel && channel.permissionsFor(botUser).has(Permissions.FLAGS.VIEW_CHANNEL))
       .map((channel: TextChannel) => channel.messages.fetch());

I'm just not sure if const botUser = this.discordClient.user; is how you get the object that represents the bot user ๐Ÿค”.

Also, I found this and it might be a cool link to add to the documentation resources on our README: https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/frequently-asked-questions.md. What do you think?

Also, I found this and it might be a cool link to add to the documentation resources on our README: https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/frequently-asked-questions.md. What do you think?

That would be great ๐Ÿ‘
We could also link to the site https://discordjs.guide/ (This site is a better resource, for beginners since the official documentation is too long and confusing at times)

I think this.discordClient.user might get the bot's user object

I tested this out, and that didn't work ๐Ÿค”

Oh, thanks for testing.

Can you update your list of options with what has been tried and if it did not work, something like

| Possible solution | Tested | Fixed |
| :--- | :--- | :--- |
| Give eddiebot admin perms(not recommended IMHO) | โœ… | ๐Ÿšซ |
| Give eddiebot "Read Message History" access to all the channels | - | - |
| Refactor the ^stats command(stats.service.ts) to account for the scenario where EddieBot doesn't have read perms to a channel and tries fetching the channel messages. | - | - |

(perhaps I could make a new list, to keep everyone up to date?)

| Possible solution | Tested | Fixed | Cons
| :--- | :--- | :--- | :--- |
| Give eddiebot admin perms(not recommended IMHO) | โœ… | โœ… | Admin perms give it power(terminator theme plays), servers usually tend to be cautious of giving admin privileges to bots... |
| Give eddiebot "Read Message History" access to all the channels | โœ… | โœ… | Long and cumbersome task, going through all channel perms |
| Refactor the ^stats command(stats.service.ts) to account for the scenario where EddieBot doesn't have read perms to a channel and tries fetching the channel messages. | ๐Ÿงช | ๐Ÿšซ | still under trial |
| Using a db for the count | โœ… | โœ… | extra db space, might be inaccurate if the bot goes offline for some time |
| Using a webhook for this(not sure how) | - | - | - |
| Since EddieBotUI is also a project we're working on, and the stats there are hardcoded, we could perhaps make an API to fetch live stats using something like selenium or something else(not sure) and then connect EddieBot to that | - | - | - |
| Using Server Insights(after making the server, a community server) and maybe scraping the page or something? (not sure if they have an API for fetching that data ๐Ÿค” ) | - | - | - |

Moreover, I have some additional info...
According to helpers on discord.js official server, all the discord messages aren't cached after a certain point of time(maybe using a db for this, might prove more efficient?)

@Vyvy-vi can you provide some information in regards to how you tested the "using a DB for the count" solution?

I'm asking because since we'll move to API calls in the future, this might be a little different. What I'm concerned about is keeping that count on our MongoDB consistent when there are multiple requests to incrementing it (this touches on concurrency).

tbh, I wasn't sure about setting a new collection on firestore, so I haven't tested that on EddieBot.
However, I have tested this out on my other bot and the main issue isn't about concurrency(that is a problem ig, tho personally I haven't seen that arise), but much rather about the consistency of data... The count would be inaccurate, if the bot is offline for say a few mins.. and ppl send messages on discord in that while

Was this page helpful?
0 / 5 - 0 ratings