Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
face-hh opened this issue Jun 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@face-hh
Copy link

face-hh commented 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);
@face-hh face-hh added the bug Something isn't working label Jun 18, 2023
@face-hh
Copy link
Author

face-hh commented 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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 💡 Open
Development

No branches or pull requests

1 participant