jorisvddonk / node-red-contrib-discord

Node-red nodes that allow you to interact with Discord.
15 stars 19 forks source link

JSON.stringify(message) Error #4

Closed aaron-neal closed 7 years ago

aaron-neal commented 7 years ago

Hi, I am new to discord.js and this nod-red node. However, I am getting the following error when i receive a message. This crashes node-red and requires a restart.

image

It is related to circular structure in the discord.js message object, happens for channel and author too. Currently working by commenting out those bits.

jorisvddonk commented 7 years ago

I'm seeing this periodically on my own instance, as well, though whenever it happens for me it doesn't always crash node-red.

Originally, the idea was to expose the original discord.js data via a property of the node-red message, so that developers could essentially write all kinds of functionality without requiring specific code in node-red-contrib-discord, but it appears that this doesn't really work. I'll probably remove this functionality completely and see if there's still a strong use case for it.

ncarlier commented 7 years ago

Hi, I have the exact same pb any time I receive a message :(

25 Jun 14:27:15 - TypeError: Converting circular structure to JSON
    at Object.stringify (native)
    at Client.e (/root/.node-red/node_modules/node-red-contrib-discord/discord/discordMessage.js:22:51)

Maybe you should surround the toJSON statement by a try catch.

Regards

jorisvddonk commented 7 years ago

Fixed in v3.0.0. Unfortunately, a lot of data is now removed (you can't retrieve a user's name anymore via msg.author.name) but I'll see if I can reïntroduce some of this data and provide a better API for sending messages to arbitrary Discord channels.

Addendum: v3.0.0 should be usable again for basic "reply" style bots, e.g. bots that reply to messages like "!help". Unfortunately, a lot of information about message authors and channel the message was received on is now only available in a rather obtuse way, which makes creating Node-red flows suboptimal. See #5 for the issue which attempts to reïntroduce this data properly.