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

messageReactionAdd events handling is broken #5078

Closed ala89 closed 3 years ago

ala89 commented 3 years ago

`\node_modules\discord.js\src\client\actions\MessageReactionAdd.js:35 const existing = message.reactions.cache.get(data.emoji.id || data.emoji.name); ^

TypeError: Cannot read property 'cache' of undefined at MessageReactionAdd.handle (\node_modules\discord.js\src\client\actions\MessageReactionAdd.js:35:40) at Object.module.exports [as MESSAGE_REACTION_ADD] (\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_REACTION_ADD.js:4:37) at WebSocketManager.handlePacket (\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31) at WebSocketShard.onPacket (\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22) at WebSocketShard.onMessage (\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10) at WebSocket.onMessage (\node_modules\ws\lib\event-target.js:132:16) at WebSocket.emit (events.js:315:20) at Receiver.receiverOnMessage (\node_modules\ws\lib\websocket.js:825:20) at Receiver.emit (events.js:315:20) at Receiver.dataMessage (\node_modules\ws\lib\receiver.js:437:14) at Receiver.getData (\node_modules\ws\lib\receiver.js:367:17) at Receiver.startLoop (\node_modules\ws\lib\receiver.js:143:22) at Receiver._write (\node_modules\ws\lib\receiver.js:78:10) at writeOrBuffer (_stream_writable.js:352:12) at Receiver.Writable.write (_stream_writable.js:303:10) at TLSSocket.socketOnData (\node_modules\ws\lib\websocket.js:900:35)`

There's no specific code to give as the root of the problem is directly the websocket message internal handing done by djs

My short investigation showed that:

class MessageReactionAdd extends Action {
  handle(data) {
    if (!data.emoji) return false;

    const user = this.getUserFromMember(data);
    if (!user) return false;

    // Verify channel
    const channel = this.getChannel(data);
    if (!channel || channel.type === 'voice') return false;

    // Verify message
    const message = this.getMessage(data, channel);
    if (!message) return false;

    // Verify reaction
    if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false;
    console.log(message)

a very poor incomplete message instance is returned from there: Message { channel: undefined, deleted: false, collector: null } without even an ID, which leads to the error next line, accessing a subproperty of an undefined property that should exist

Further details:

Relevant client options:

SpaceEEC commented 3 years ago

I am unable to reproduce this error. I can react to uncached and cached messages just fine. (I just tested a bit around since you did not provide any concrete steps to reproduce this error.)


Please make sure this error actually is reproducible using minimal code.

Extensions of structures or modification of the lib are not explicitly mentioned here, therefore they shouldn't be included:

Message { channel: undefined, deleted: false, /* -> */ collector: null /* <- */ }

That is not a property of discord.js' Message class.


If you can still reproduce this error using minimal code, you may want to provide steps to reproduce this, including further information about your cache situation and anything else that could be related (the more the better). As well as the actual minimal code you used to reproduce this error. (Even if it's just the client instantiation and its login)

ala89 commented 3 years ago

Oh you're kinda right actually, it was just a mistake of mine when extending structures Sorry for this