discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.39k stars 3.97k forks source link

Guilds not getting members cached #1870

Closed SirDeadlystrike closed 6 years ago

SirDeadlystrike commented 7 years ago

Please describe the problem you are having in as much detail as possible: Guilds are seemingly at random having no member objects. Even after multiple messages received and minutes later. guild.me and message.member are undefined along with everyone else. These are not new guilds.

Further details:

1Computer1 commented 7 years ago

Is your own bot invisible? If so, that would explain why the bot member is not cached.
Otherwise, any uncached members can be fetched with guild.fetchMember.
Edit: guild.members.fetch on master.

SirDeadlystrike commented 7 years ago

No, the bot is not invisible. While yes, i could check if the member object of both the bot and the message sender is cached on every command, and if not fetch it. That seems like a band-aid solution to larger problem of guilds having no members cached ever.

I don't think this is a intended behavior especially when its happening to only a few guilds at a time.

Every time i restart the bot within 2hrs there is 1-2 people complaining that things arn't working which are caused by both message.member and guild.me returning undefined.

1Computer1 commented 7 years ago

Are these guilds over 250 members?

SirDeadlystrike commented 7 years ago

No 48 members on the most recent noted issue guild

SirDeadlystrike commented 7 years ago

A bit more info. A small 22 man guild went from working fine to no longer having valid objects for the bot member or any message member. For this specific guild the issue persisted them kicking and re-inviting the bot, and was only fixed once i rebooted the bot as a whole

vladfrangu commented 7 years ago

Did you set fetchAllMembers to true in your client settings? You can try that, and see if that fixes it

devsnek commented 7 years ago

the member for the client is always sent regardless of guild size, client status, fetchAllMembers settings, etc

iCrawl commented 7 years ago

You should not rely on msg.member to always be present @gmedeadlystrike If a member is invis for quite some time you would have to fetch his member each and every restart of your bot. And its not really a band-aid to fetch every time someone triggers a command because if the person is already in cache you get the cached member back.

SirDeadlystrike commented 7 years ago

I understand, I guess I will make sure the member object is present. It does however look like there is a issue with the client not having a member object cached as was noted here https://github.com/Gawdl3y/discord.js-commando/pull/70

WRMSRwasTaken commented 7 years ago

Hmmm. seems relatetd to my issue: https://github.com/hydrabolt/discord.js/issues/1848

amishshah commented 7 years ago

Could you send me any stacktraces if you have them, and also debug guild.members.size at the time of the error? I want to see if the members cache is being cleared accidentally.

SirDeadlystrike commented 7 years ago

@hydrabolt - guild.members.size was infact 0 during a couple of these issues

amishshah commented 7 years ago

@gmedeadlystrike do you know if the server experience any outages in this time?

amishshah commented 7 years ago

Also, are you using any bot frameworks? Can you also debug client.users.filter(u => !u.id).size at the time of error.

amishshah commented 7 years ago

Could you try using master on the lastest commit ^ 👍

amishshah commented 7 years ago

Seems to be fixed for @dragonfire535, I'll give it a few more days before officially declaring as fixed 👍

dragonfire535 commented 7 years ago

It's back, attempting to get more information.

SirDeadlystrike commented 7 years ago

Yep, issue is still happening

SirDeadlystrike commented 7 years ago

So i got some more info on this issue. I use the commando framework which by default will await the caching of the client and user member objects before running commands to make sure their available. You can see an example of this in this PR https://github.com/Gawdl3y/discord.js-commando/pull/73 - with such a check in place I have not noticed any instances of the user member object not being in cache, but in fact still on occasion notice the clientuser's member object being undefined. @hydrabolt

iCrawl commented 7 years ago

So... it's still in cache but sometimes still undefined?

I don't quite get what you are saying there.

SirDeadlystrike commented 7 years ago

Sorry, maybe i was unclear. The method you would normally use to ensure and force the member objects (client + user) into cache is in place and being executed, however a few cpu cycles later the clientuser member object can return undefined, im not sure if that means its no longer in the cache or if guild.me is returning undefined for another reason. One line before I call guild.me I am checking that the guild still exists

bdistin commented 7 years ago

Can anyone here try: npm i -S bdistin/discord.js#patch-30 and watch and see if the issue shows up, or if that pr fixes the issue?

dragonfire535 commented 7 years ago

This shouldn't be closed 👀

SirDeadlystrike commented 7 years ago

@dragonfire535 ok, I have not seen this issue pop up in a week or so now, so 🤷‍♂️

amishshah commented 7 years ago

@gmedeadlystrike have you been able to reproduce this in the last few days? :s

FireController1847 commented 7 years ago

@hydrabolt I'm not sure if this is related but filtering from GuildMembers in a Guild from Message gives many statuses undefined.

const totalOffline = members.filter(m => m.user.presence.status == "offline").size;

If you log the status, most of them are appearing offline.

SirDeadlystrike commented 6 years ago

from my observations, this issue all but vanished after the "kick-fix" where that seemed to resolve almost all instances of this. Recently I have begun to get reports of this issue occurring with my bot once again.

I don't have a repeatable chain of events to trigger it as was the case last time just yet, will update if i have more info

AtoraSuunva commented 6 years ago

I've just had to deal with a similar issue on v11.3.0, where lots of members weren't getting cached.

On a small (11 member) server, everything worked as expected, but on a larger (7015 member) server things broke.

Users who just joined would have member sent correctly for guildMemberAdd, but trying message.member on one of their messages or trying to fetch them from guild.members returns undefined.

Trying guild.fetchMembers() didn't help, as the number of cached members before/after were the same guild.fetchMembers() not working

Changing to most recent commit (e576387fea2a973eefe298a6f3610eb0d8b54999) fixes all of this: members are cached on join and message.guild.members.fetch() fetches all 7k members

Lewdcario commented 6 years ago

@AtlasTheBot, I cannot verify your claims. I have done the same on 11.3 and it updated the cache for me. As for the other behaviour, I believe that you are confusing it with a different issue. Members are not cached if their status is offline in a large guild. Additionally, it should be returning null over undefined, if that was a mistake. If it is not, well, then that is concerning. But if it is truly null, a simple guild.fetchMember() would do with their id in the message event, that is how we do it in general to grab the cached member.

appellation commented 6 years ago

I have received a report from one of my bot's users that indicates this bug is still occurring. The user reported that all guild members were not considered being in a voice channel despite actually being in a voice channel. I'm running a slightly outdated version of master (3e3674b1af200eb3947018f210bdf49b0e200b1b). Unfortunately I cannot really provide more information than has already been reported, other than to provide a more recent commit hash (assuming @AtlasTheBot's comment is unrelated to this bug). I will update to a more recent version of master and see if I still have this bug.

iCrawl commented 6 years ago

This issue has been pretty stale for a few months now, open a new issue if this still persists please.

dylanh724 commented 4 years ago

Error: Invalid or uncached id provided