Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot crashes after disabling some caches #6290

Closed
Vicente015 opened this issue Aug 3, 2021 · 9 comments
Closed

Bot crashes after disabling some caches #6290

Vicente015 opened this issue Aug 3, 2021 · 9 comments

Comments

@Vicente015
Copy link
Contributor

Please describe the problem you are having in as much detail as possible:
The client crashed after disabling the member and user cache (GuildMemberManager: 0, UserManager: 0) and listening to the userUpdate event. I was expecting it to be emitted with some data or partial data.

Error:

/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/discord.js/src/client/actions/UserUpdate.js:11
    const oldUser = newUser._update(data);
                            ^

TypeError: Cannot read property '_update' of undefined
    at UserUpdateAction.handle (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/discord.js/src/client/actions/UserUpdate.js:11:29)
    at Object.module.exports [as USER_UPDATE] (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/discord.js/src/client/websocket/handlers/USER_UPDATE.js:4:29)
    at WebSocketManager.handlePacket (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/discord.js/src/client/websocket/WebSocketManager.js:345:31)
    at WebSocketShard.onPacket (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/discord.js/src/client/websocket/WebSocketShard.js:443:22)
    at WebSocketShard.onMessage (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/discord.js/src/client/websocket/WebSocketShard.js:300:10)
    at WebSocket.onMessage (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (events.js:376:20)
    at Receiver.receiverOnMessage (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/ws/lib/websocket.js:970:20)
    at Receiver.emit (events.js:376:20)
    at Receiver.dataMessage (/media/vicente/Secundario/Desktop/Proyectos/djs-limited-caching/node_modules/ws/lib/receiver.js:517:14)

Include a reproducible code sample here, if possible:

const { Client, Options } = require('discord.js')

const client = new Client({
  intents: [
    'GUILDS',
    'GUILD_BANS',
    'GUILD_MEMBERS',
    'GUILD_EMOJIS_AND_STICKERS',
    'GUILD_INTEGRATIONS',
    'GUILD_WEBHOOKS',
    'GUILD_INVITES',
    'GUILD_VOICE_STATES',
    'GUILD_PRESENCES',
    'GUILD_MESSAGES',
    'GUILD_MESSAGE_REACTIONS',
    'GUILD_MESSAGE_TYPING',
    'DIRECT_MESSAGES',
    'DIRECT_MESSAGE_REACTIONS',
    'DIRECT_MESSAGE_TYPING'
  ],
  makeCache: Options.cacheWithLimits({
    GuildMemberManager: 0,
    UserManager: 0
  }),
  partials: [
    'USER',
    'CHANNEL',
    'GUILD_MEMBER',
    'MESSAGE',
    'REACTION'
  ]
})

client.on('ready', () => {
  console.log('Bot ready')
})

client.on('userUpdate', (oldUser, newUser) => {
})

client.login(process.env.TOKEN)

Further details:

  • discord.js version: 13.0.0-dev.t1627992462.35fa3b3
  • Node.js version: 14.17.0
  • Operating system: Linux 5.4 Zorin OS 15.3
  • Priority this issue should have – please be realistic and elaborate if possible:

Relevant client options:

  • partials: Same as code sample
  • gateway intents: Same as code sample
  • other: none
@iCrawl
Copy link
Member

iCrawl commented Aug 3, 2021

Thats intended, we just didn't document it so far.

@iCrawl iCrawl closed this as completed Aug 3, 2021
@iCrawl
Copy link
Member

iCrawl commented Aug 3, 2021

Whoops, didn't mean to close this.

@iCrawl iCrawl reopened this Aug 3, 2021
@iCrawl
Copy link
Member

iCrawl commented Aug 3, 2021

We would have to investigate completely disabling the UserManager though.

Chances are completely disabling it will be unsupported. Our userUpdate event isn't exactly the raw update from discord.

You could try setting it to like 10(?) or so, this should solve your problem. Or even 5 for that matter.

Also disabling your GuildMember cache like that will make you unable to check for your own clients permissions, is that intended in your use case?

@Vicente015
Copy link
Contributor Author

Also disabling your GuildMember cache like that will make you unable to check for your own clients permissions, is that intended in your use case?

No, that was not my intention.

In this case the error happened when a user changed their username, if it was emitted by a gateway event it would be useful in case a developer wants to reduce memory consumption and just cache the client using the keepOverLimit option, but also be able to listen to the userUpdate event to provide logging.

@Vicente015
Copy link
Contributor Author

But I know it might be better to consider not supporting disabling that cache and consider fixing it in future versions.

@iCrawl
Copy link
Member

iCrawl commented Aug 3, 2021

With the current way this event is set up (since it's not a real event) and how much work it would be, this is sadly unfeasible in v13.

BUT like I said, try lowering the number to something more feasible that still nets you a memory benefit, like 10-100 (mind you, users or members are usually no problem until you reach like 200-500k of them).

@yuvapoojary
Copy link

By making UserManager or GuildMemberManager's limit to 10-20 , will solve above issue ?.

@Vicente015
Copy link
Contributor Author

Yes, this issue is solved by setting the limit to 10

@yuvapoojary
Copy link

Yea tried it.
Literally my bot uses less than 150mb ,it is in 2000+ servers

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants