Repository: discordjs/discord.js

Issue #4821: Error due to PR #4791 Cannot read property user of undefined
Created: 2020-09-14T20:52:33Z
Please describe the problem you are having in as much detail as possible:
Ever since the PR #4791 I noticed that I received an error that I never used to get. The stack trace is originating from Action.js#96:50. Currently I'm not sure what happened at the time of the error but I'll update on that when I figure out when it was thrown.
The stack trace is
Uncaught Exception Error:
TypeError: Cannot read property 'user' of undefined
     at TypingStart.getUserFromMember (/opt/highlight/node_modules/discord.js/src/client/actions/Action.js:96:50)
     at TypingStart.handle (/opt/highlight/node_modules/discord.js/src/client/actions/TypingStart.js:15:23)
     at Object.module.exports [as TYPING_START] (/opt/highlight/node_modules/discord.js/src/client/websocket/handlers/TYPING_START.js:4:30)
     at WebSocketManager.handlePacket (/opt/highlight/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
     at WebSocketShard.onPacket (/opt/highlight/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
     at WebSocketShard.onMessage (/opt/highlight/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
     at WebSocket.onMessage (/opt/highlight/node_modules/ws/lib/event-target.js:125:16)
     at WebSocket.emit (events.js:314:20)
     at Receiver.receiverOnMessage (/opt/highlight/node_modules/ws/lib/websocket.js:797:20)
     at Receiver.emit (events.js:314:20)

Include a reproducible code sample here, if possible:
The reproducible code isn't exactly how it's actually setup in my code. Each listener is in it's own file same with the class method. This is just a basic example to show how I use it.
const { EventEmitter } = require('events');

this.client.highlightListeners = new EventEmitter();

this.client.ws.on('TYPING_START', (data) => {
	this.client.emit('onUserActivity', { id: data.channel_id, guild: Boolean(data.guild_id) }, { id: data.user_id });
});

this.client.on('onUserActivity', async(channel, user) => {
	// emitted whenever a user does something that would cause them to see recent messages in channel_id
	if (channel && channel.guild) {
		try {
			const user_settings = (await this.client.gateways.get('users').provider.db.table('users').run()).find((u) => u.id === user.id);
			await this.client.redisdb.set(`received_activity.${channel.id}.${user.id}`, true, 'EX', (user_settings && user_settings.notification_settings && user_settings.notification_settings.activity_cooldown) || 10); // set that the user was recently active in the channel
			this.client.highlightListeners.emit(`onUserActivity_${user.id}_${channel.id}`, channel.id, user.id);
		} catch (error) {
			this.client.console.error(error.stack || error.toString());
		}
	}
});

// this is a method from in one of my classes that uses the event.
async wait_for(event, triggered_channel_id, highlighted_member_id, timeout) {
	return new Promise(async(resolve, reject) => {
		const time = setTimeout(() => { return this.client.highlightListeners.emit(event, undefined, undefined, true) }, timeout);
		const listen = (async() => {
			return this.client.highlightListeners.once(event, async(channel_id, user_id, force_reject = false) => {
				if (force_reject) {
					if (time) clearTimeout(time);
					return resolve(`[${highlighted_member_id}] Member was not seen active.`);
				}
				if (user_id && user_id === highlighted_member_id && channel_id && channel_id === triggered_channel_id) {
					if (time) clearTimeout(time);
					return reject(`[${highlighted_member_id}] Member was seen active.`);
				} else {
					return await listen(); // requeue the listener if criteria failed (this method prevents multiple of the same listeners from being set)
				}
			});
		});
		return await listen();
	});
}
Further details:

discord.js version: 12.3.1
Node.js version: Node v14.10.1
Operating system: Ubuntu 18.04
Priority this issue should have – please be realistic and elaborate if possible: this kinda depends on if it's something I may have missed or if it's an issue with discord.js.

Relevant client options:

partials: none
gateway intents: none
other: none



 I have also tested the issue on latest master, commit hash: 01ceda5

Duplicate issue #4840: TypeError on MESSAGE_REACTION_ADD
Created: 2020-09-22T18:25:00Z
Please describe the problem you are having in as much detail as possible:
Got few times a TypeError when receiving a MESSAGE_REACTION_ADD event.


Further details:

discord.js version: latest master
Node.js version: v12.18.3
Operating system: debian 9
Priority this issue should have – please be realistic and elaborate if possible: normal

Relevant client options:

partials: ['REACTION','MESSAGE']
gateway intents: 13999
other: none



 I have also tested the issue on latest master, commit hash:

Closing comment (2020-09-22T20:33:28Z): Duplicate of #4821, which has been fixed by #4822.

I am using the very latest version of d.js, this merge inclued.
This means it is not fixed.