bug: MessageReact event crashes with: TypeError: reactions.get is not a function #29

Open
opened 2026-02-16 12:26:49 -05:00 by yindo · 1 comment
Owner

Originally created by @face-hh on GitHub (Jun 18, 2023).

What happened?

This snippet of code causes the above error:

		case 'MessageReact': {
			const message = client.messages.getOrPartial(event.id);
			if (message) {
				const reactions = message.reactions;

				const set = reactions.get(event.emoji_id);

... when a messageReactionAdd event listener exists:

// ...
this.options.client.on('messageReactionAdd', this.listener);
// ...

This code was used to trigger the error:

				await msg.clearReactions();
				await msg.react(encodeURIComponent('❌'));

Explanation: The event tries to get which reaction was added (?), but, since clearReactions ran, message.reactions is {}, causing the reactions.get is not a function error, since reactions is not a Map anymore.

My temporary fix:

		case 'MessageReact': {
			const message = client.messages.getOrPartial(event.id);
			if (message) {
				let reactions = message.reactions;

				if (!(reactions instanceof Map)) reactions = new Map();

				const set = reactions.get(event.emoji_id);
Originally created by @face-hh on GitHub (Jun 18, 2023). ### What happened? This snippet of code causes the above error: ```js case 'MessageReact': { const message = client.messages.getOrPartial(event.id); if (message) { const reactions = message.reactions; const set = reactions.get(event.emoji_id); ``` ... when a `messageReactionAdd` event listener exists: ```js // ... this.options.client.on('messageReactionAdd', this.listener); // ... ``` This code was used to trigger the error: ```js await msg.clearReactions(); await msg.react(encodeURIComponent('❌')); ``` Explanation: The event tries to get which reaction was added (?), but, since `clearReactions` ran, `message.reactions` is `{}`, causing the `reactions.get is not a function` error, since `reactions` is not a `Map` anymore. My temporary fix: ```js case 'MessageReact': { const message = client.messages.getOrPartial(event.id); if (message) { let reactions = message.reactions; if (!(reactions instanceof Map)) reactions = new Map(); const set = reactions.get(event.emoji_id); ```
yindo added the bug label 2026-02-16 12:26:49 -05:00
Author
Owner

@face-hh commented on GitHub (Jun 19, 2023):

In case it helps, this happened on 7.0.0-beta.7.

The same issue seems to occur on the "MessageUnreact" event:

		case 'MessageUnreact': {
			const message = client.messages.getOrPartial(event.id);
			if (message) {
				const set = message.reactions.get(event.emoji_id);

where "message.reactions" is {}, resulting in TypeError: message.reactions.get is not a function, when there are 2 reactions on a message (me & the bot), and I unreact.

edit: fixed it with:

		case 'MessageUnreact': {
			const message = client.messages.getOrPartial(event.id);
			if (message) {
				let reactions = message.reactions;

				if (!(reactions instanceof Map)) reactions = new Map();

				const set = reactions.get(event.emoji_id);
@face-hh commented on GitHub (Jun 19, 2023): In case it helps, this happened on `7.0.0-beta.7`. The same issue seems to occur on the "MessageUnreact" event: ```js case 'MessageUnreact': { const message = client.messages.getOrPartial(event.id); if (message) { const set = message.reactions.get(event.emoji_id); ``` where "message.reactions" is `{}`, resulting in `TypeError: message.reactions.get is not a function`, when there are 2 reactions on a message (me & the bot), and I unreact. edit: fixed it with: ```js case 'MessageUnreact': { const message = client.messages.getOrPartial(event.id); if (message) { let reactions = message.reactions; if (!(reactions instanceof Map)) reactions = new Map(); const set = reactions.get(event.emoji_id); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stoatchat/javascript-client-sdk#29