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

GuildMemberRoleManager.js Error #6876

Closed Instinzts closed 2 years ago

Instinzts commented 3 years ago

Issue description

  1. Turn on the bot and message its sent, when bots gets online. After it just disconnects my bot after sending the message below. Try updating both node and discord.js but it doesnt seem to fix it.

Code sample

/home/container/node_modules/discord.js/src/managers/GuildMemberRoleManager.js:36
    return this.guild.roles.cache.filter(role => this.member._roles.includes(role.id)).set(everyone.id, everyone);
                                                                                                    ^

TypeError: Cannot read property 'id' of undefined
    at GuildMemberRoleManager.get cache [as cache] (/home/container/node_modules/discord.js/src/managers/GuildMemberRoleManager.js:36:101)
    at GuildMember.get permissions [as permissions] (/home/container/node_modules/discord.js/src/structures/GuildMember.js:209:39)
    at /home/container/events/ready.js:7:28
    at Map.filter (/home/container/node_modules/@discordjs/collection/dist/index.js:159:17)
    at Client.<anonymous> (/home/container/events/ready.js:7:8)
    at Client.emit (node:events:406:35)
    at WebSocketManager.triggerClientReady (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:383:17)
    at WebSocketManager.checkShardsReady (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:366:10)
    at WebSocketShard.<anonymous> (/home/container/node_modules/discord.js/src/client/websocket/WebSocketManager.js:188:14)
    at WebSocketShard.emit (node:events:394:28)
    at Timeout._onTimeout (/home/container/node_modules/discord.js/src/client/websocket/WebSocketShard.js:490:14)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

discord.js version

13.2.0

Node.js version

v16.11.0

Operating system

Windows 10

Priority this issue should have

High (immediate attention needed)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GUILDS, GUILD_MEMBERS

I have tested this issue on a development release

No response

kevinbioj commented 3 years ago

That bug is a side-effect that may happen if you disable, or set a very low limit, to the RoleManager cache. The library assumes the role cache always includes the @everyone role, statement that is no longer valid if you disabled the associated cache.

Limiting cache capacities is something that must be done with careful precaution and advanced testing, and should only be done if necessary anyway.