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

Open
#78 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Domain
api

Research direction

Start at the MessageReact handler shown in the issue and inspect how message.reactions is updated when the messageReactionAdd listener runs after clearReactions. Reproduce the sequence with clearReactions followed by react, then verify that the event no longer crashes when reactions is an object rather than a Map.

Written by the indexing model from the issue text.

Description

bug
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);
Dominant language
TypeScript
Stars
285
Forks
108
Avg merge
16h 49m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stoatchat/javascript-client-sdk

All issues in stoatchat/javascript-client-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.