EddieBot: BUG: Stats command total messages broken

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 19 (17 by maintainers)

Most upvoted comments

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. - -

@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?

Thank you for raising this issue and for all the information you included in it 👍