#Property comparison weirdness
1 messages ยท Page 1 of 1 (latest)
No I meant the value of the msg object from your debug output.
Property comparison weirdness
The msg object from your example or from my implementation? The above copy is from my implementation
From yours. I know mine works.
Oh. It looked like a Node Red export. Maybe I'm the stupid one ๐
Okay import that: https://dpaste.org/pAGLC/raw
I replaces the whole msg object with your output and it still works fine here.
I modified it to have a debug output: #1274748148669222933 message
But it basically replaces the whole msg with what you had so I can test it over and over again exactly as if I had your input.
I'm a little confused about what to try now, seeing as the exact same msg works from a function
hang on, now if I skip the function it's working
Sorry no ignore me
I'd try without JSONata.
My message comes from a plugin node, I don't really have any control over it ๐ฅ
Your change node uses JSONata.
I'm not even using a change node now, it's literally this
Add a whole msg debug node after the discord node. Then please share the flow and the debug's output.
Debug output:
{"_msgid":"18dee81b38c5cd3c","payload":"test","channel":{"type":0,"guild":"1226774624331890708","guildId":"1226774624331890708","permissionOverwrites":["1226774624331890708","1264841235903025183"],"messages":["1274753055379951657"],"threads":[],"nsfw":false,"flags":0,"id":"1264841748308430984","name":"bot-test","rawPosition":3,"parentId":"1226774624834949211","topic":null,"lastMessageId":"1274753055379951657","defaultThreadRateLimitPerUser":null,"rateLimitPerUser":0,"createdTimestamp":1721632172420},"member":{"guildId":"1226774624331890708","joinedTimestamp":1712556262828,"premiumSinceTimestamp":null,"nickname":null,"pending":false,"communicationDisabledUntilTimestamp":null,"userId":"130568230078119936","avatar":null,"flags":0,"displayName":"kridges","roles":["1264843949072187402","1226774624331890708"],"avatarURL":null,"displayAvatarURL":"https://cdn.discordapp.com/avatars/130568230078119936/a_c0aa28b634c496ea913824d802113590.gif"},"memberRoleNames":[{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1264843949072187402","name":"HomeController","color":0,"hoist":false,"rawPosition":1,"permissions":"0","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1721632697123},{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1226774624331890708","name":"@everyone","color":0,"hoist":false,"rawPosition":0,"permissions":"2222085186637377","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1712556262811}],"memberRoleIDs":[{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1264843949072187402","name":"HomeController","color":0,"hoist":false,"rawPosition":1,"permissions":"0","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1721632697123},{"guild":"1226774624331890708","icon":null,"unicodeEmoji":null,"id":"1226774624331890708","name":"@everyone","color":0,"hoist":false,"rawPosition":0,"permissions":"2222085186637377","managed":false,"mentionable":false,"flags":0,"tags":{},"createdTimestamp":1712556262811}],"data":{"channelId":"1264841748308430984","guildId":"1226774624331890708","id":"1274753055379951657","createdTimestamp":1723995212169,"type":0,"system":false,"content":"test","authorId":"130568230078119936","pinned":false,"tts":false,"nonce":"1274753055773949952","embeds":[],"components":[],"attachments":[],"stickers":[],"position":null,"roleSubscriptionData":null,"resolved":null,"editedTimestamp":null,"mentions":{"everyone":false,"users":[],"roles":[],"crosspostedChannels":[],"repliedUser":null,"members":[],"channels":[]},"webhookId":null,"groupActivityApplicationId":null,"applicationId":null,"activity":null,"flags":0,"reference":null,"interaction":null,"poll":null,"cleanContent":"test"},"author":{"id":"130568230078119936","bot":false,"system":false,"flags":0,"username":"kridges","globalName":"kridges","discriminator":"0","avatar":"a_c0aa28b634c496ea913824d802113590","banner":"a_46c8a6d2914e6f4690e7201fd99059e4","accentColor":11592959,"avatarDecoration":null,"createdTimestamp":1451200291891,"defaultAvatarURL":"https://cdn.discordapp.com/embed/avatars/1.png","hexAccentColor":"#b0e4ff","tag":"kridges","avatarURL":"https://cdn.discordapp.com/avatars/130568230078119936/a_c0aa28b634c496ea913824d802113590.gif","displayAvatarURL":"https://cdn.discordapp.com/avatars/130568230078119936/a_c0aa28b634c496ea913824d802113590.gif","bannerURL":"https://cdn.discordapp.com/banners/130568230078119936/a_46c8a6d2914e6f4690e7201fd99059e4.gif"}}
Flow
My addon is 18.0.5 btw.
I'm pretty sure this will be identical bar some timestamps to what you put into the function
Hmm. All I did was replacing the discord node. Funky: https://dpaste.org/rN5kH/raw
The weird thing is I can definitely write conditions on the member.displayName value, which is obviously not within an array
That's why I think it's an array thing
Perhaps there's a special character that is not going in the function but is persisting from the discord node?
Makes no sense through if my flows work fine for you and do exactly the same.
That was my thought and why I wanted the output.
Again this works for me
It's gotta be something to do with the Discord node, and somehow not impacting all values
Let's try something really simple then. Add this node after your discord node
[{"id":"4464cb801fe3c9f7","type":"function","z":"cae8eceb71b2cae3","name":"Check for msg.memberRoleNames[0].name","func":"node.warn(`msg.memberRoleNames[0].name: \"${msg.memberRoleNames[0].name}\"`);\n\nif (msg.memberRoleNames[0].name == \"HomeController\") {\n node.warn(`HomeController found`);\n} else {\n node.warn(`HomeController not found`);\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":380,"wires":[[]]}]
TypeError: Cannot read properties of undefined (reading 'name')
Try this variant
[{"id":"58ee766f8c876f10","type":"function","z":"cae8eceb71b2cae3","name":"Check for msg.memberRoleNames[0].name","func":"node.warn(msg);\nnode.warn(`msg.memberRoleNames[0].name: \"${msg.memberRoleNames[0].name}\"`);\n\nif (msg.memberRoleNames[0].name == \"HomeController\") {\n node.warn(`HomeController found`);\n} else {\n node.warn(`HomeController not found`);\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":280,"wires":[[]]}]
Can you expand the warn object.
I don't really understand what's happening here.
I'm glad I'm not the only one
There's clearly something going on outside of the message
But maybe these tests still helped somewhat.
Is there a method to convert a whole object into a string and then try a compare on that?
It's almost 2am on a work night so I'm going to come back to this another time, maybe after a version upgrade. I'm not awfully hopeful that it'll change anything but you never know :D
Thanks for your help @spring apex , really appreciate it
Not directly. It would be a mess to convert JSON to a single string, no?
There's a JSON node though to convert objects to JSON and JSON.stringify for the function node.
Sure, but it seems to only fail with array values. It would at least help understand it better
the json node made it work
Clearly it's a pretty shit solution but at least now nodered can find the value I'm looking for
On the plus side it's potential future proofing, ensuring that it checks all items in the array, which covers me in case they change order
You can do this via JSONata too with something like
[$contains(name, "HomeController")]
Not very trivial though and I already forgot most of JSONata's syntax.
Sorry for another dumb question - what node should this be in?
Whatever you want. In my case I use a change node to extract it.
This is my first Nodered project so my brain is empty
I use this to extract power plugs and other things from my Zigbee2MQTT's devices message.
It's a big hack so I can reconfigure their reporting interval which gets reset sometimes. To do this I need to extract their names and this is what I came up with since they all share a prefix.
This works directly in the switch
I think that's a cleaner solution
One less node at least
I hate that I don't know what causes this weird behavior though.