Skip to content

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

@face-hh

Description

@face-hh

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions