discordjs / discord.js

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

New guild emojis aren't being cached after running bot for a few days. #2332

Closed iamtraction closed 6 years ago

iamtraction commented 6 years ago

Please describe the problem you are having in as much detail as possible: After my bot runs continuously for a few days, if someone adds any new (custom) emojis to their guild, those newly added (custom) emojis aren't being cached to the Guild.emojis Collection anymore. Another caching issue perhaps?

Include a reproducible code sample here, if possible:

message.guild.emojis

only contains the entries for old (custom) emojis.

screenshot

Further details:

SpaceEEC commented 6 years ago

Can you try running 11.3-dev for a while and see whether you run into this issue there as well? This could have been fixed with https://github.com/discordjs/discord.js/commit/3df374192295805a2a3975a19501f7b4e0591646.

If not, can you tell me what message.guild === client.guilds.get(message.guild.id) evaluates to? (When an emoji is missing, that is)

iamtraction commented 6 years ago

I can't use 11.3-dev in production, it might break something and users might face problems. But next time I notice emojis are not being cached, I'll test the equality for message.guild and client.guilds.get(message.guild.id) and let you know.

devdutchy commented 6 years ago

11.3-dev doesn't have any breaking changes, it should be safe to run in a production environment.

iamtraction commented 6 years ago

By the way, I've also noticed that Discord was down right before this issue starts happening. I've seen this last two times Discord was down. Could that have anything to do with it?

iCrawl commented 6 years ago

No, most likely not.

You have to install 11.3-dev and see if this solves the issue. Minor version increases do not come with breaking changes, only bug fixes to problems you have right now.

iamtraction commented 6 years ago

Okay, after some days of monitoring, I found that the issue starts after a socket hang up. And I also found that it's not just guild emojis, not even guild members are cached anymore. I kicked & banned two users from a guild, and guild.members.size still has the old value.

But if I do client.guilds.get('GUILD_ID').members.size or client.guilds.get('GUILD_ID').emojis.size it has the updated values, unlike message.guild.

And so, to answer @SpaceEEC 's question, message.guild === client.guilds.get(message.guild.id) evaluates to false.

This was 11.3. I'll start testing with 11.3-dev from this Sunday.

joe27g commented 6 years ago

Ditto to the previous comment. All events are received properly, but message.guild, member.guild, and similar references all fail to update. I've tested this extensively on 11.3 and 11.3-dev as well, same issue happens after a reconnect. But after a bit more testing, dc92582 seems to fix this completely :)

Note: imo, this should be p: high - This issue effectively "freezes" a guild for a bot; i.e. using a reference like message.member.permissions.has or message.member.roles could return an old value and give people access to things that they shouldn't have access to.