Hello Node-Red community! I'm having a bit of trouble with a flow I'm making for a Discord Bot that takes a message, parses it, then outputs each number to its own text file. I have each half working independently. If I disconnect the file node, it will output the desired payload into debug. Then, if I reattach the file node, and disconnect the discord message node, I can inject a typical message and it will output the files as needed. The issue seems to occur when I have both attached. I keep getting the error: "RangeError: Maximum call stack size exceeded" when I attempt to parse the discord messages then output to file. It seems to be the second function node that throws the error. Is there an inefficiency in the way I've written that second function? I've tried the delay/message limit node in a few locations, that didn't make any difference. Am I missing something simple?
[{"id":"f653e254f7e1139a","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"989c7578cc7ab40c","type":"file","z":"f653e254f7e1139a","name":"","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":880,"y":60,"wires":[[]]},{"id":"a2b7bb90be583841","type":"function","z":"f653e254f7e1139a","name":"","func":"msg.payload=msg.payload.split(\":\");\nmsg.payload=msg.payload[1].split(\"Result\");\nmsg.payload=msg.payload[0].split(\",\"); \nconst regex = /\\D/;\n\nfor (var i = 0; i < msg.payload.length; i++){\n for(var e = 0; e < msg.payload[i].length+2;e++){\n msg.payload[i] = msg.payload[i].replace(regex, \"\")\n }\n msg.payload[i]=msg.payload[i].replace(\" \",\"\");\n}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":60,"wires":[["ae59b41a057b3d3f"]]},{"id":"ae59b41a057b3d3f","type":"function","z":"f653e254f7e1139a","name":"","func":"convertToDice = msg.payload\nmsg.filename = \"\"\nfor (i = 0; i < convertToDice.length; i++){\n diceNum = \"dice\" + (i+1)\n msg.filename = \"/home/pi/Documents/\" + diceNum + \".txt\";\n msg.payload = convertToDice[i];\n node.send(msg);\n node.done();\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":60,"wires":[["e8823236e6e79e37","989c7578cc7ab40c"]]},{"id":"a1f4910557681a62","type":"inject","z":"f653e254f7e1139a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Jordacai Roll: [6, 5, 3, 2, 3, 5] Result: 16","payloadType":"str","x":330,"y":100,"wires":[["a2b7bb90be583841"]]},{"id":"e8823236e6e79e37","type":"debug","z":"f653e254f7e1139a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":100,"wires":[]},{"id":"9140f1140b3c4efa","type":"discord-get-messages","z":"f653e254f7e1139a","name":"","token":"","channels":"#roll-dice","x":150,"y":60,"wires":[["ea7d2c6a6eaa089b"]]},{"id":"ea7d2c6a6eaa089b","type":"switch","z":"f653e254f7e1139a","name":"","property":"member.user.username","propertyType":"msg","rules":[{"t":"regex","v":"Dice Maiden","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":330,"y":60,"wires":[["a2b7bb90be583841"]]}]