Markoudstaal / node-red-contrib-discord-advanced

Recieve, send, edit and delete Discord messages in node-red.
MIT License
47 stars 16 forks source link

Advanced message format #27

Closed jerome6994 closed 2 years ago

jerome6994 commented 2 years ago

Hello, I'm new to Node Red. I discovered your work which seems to meet my expectations when reading it but I find it difficult to put it into practice I'm doing a test on a classic flow in order to see all the options on a message but I have errors so I decided to reduce the number of options in order to target the error. I have this error: TypeError: Cannot read properties of undefined (reading 'content') and I don't see who generates it image

My flow is : image

My function is :

`const msg1 = {};

msg1.channel = '911259838544228402'; msg1.embeds = { "title": 'Test de Message Evolué', "description": 'Description du message', };

return msg1;`

image

Thank you for your help in correcting my error.

javis86 commented 2 years ago

the default behaviour of the discordMessageManager is to request for a text inside msg.payload. If you want to send only embed without any text you can do the follow: msg.payload = ""; image

jerome6994 commented 2 years ago

Thank you for your quick response, however I do not understand the subtlety of this one. I think it comes from my youth on Node Red and its environment but I can't fix what I started doing at all I wanted to start with a simple message and then increase the difficulty with the insertion of images from my cameras etc. Your work is excellent for a novice like me it is difficult without an example from start to finish but I do not despair

javis86 commented 2 years ago

The most simple message with de discordMessageManager:

[
    {
        "id": "bbe6e51927b4a2c0",
        "type": "debug",
        "z": "4bde5831221f6bb2",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 770,
        "y": 60,
        "wires": []
    },
    {
        "id": "709a8f3baf4e320e",
        "type": "discordMessageManager",
        "z": "4bde5831221f6bb2",
        "name": "",
        "channel": "",
        "token": "",
        "x": 550,
        "y": 60,
        "wires": [
            [
                "bbe6e51927b4a2c0"
            ]
        ]
    },
    {
        "id": "ca2521669295ab88",
        "type": "function",
        "z": "4bde5831221f6bb2",
        "name": "",
        "func": "msg.payload = \"Hello there\";\nmsg.channel = \"111111111111111\"; // Your channel ID\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 60,
        "wires": [
            [
                "709a8f3baf4e320e"
            ]
        ]
    },
    {
        "id": "373865a8cf8a50c6",
        "type": "inject",
        "z": "4bde5831221f6bb2",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 150,
        "y": 60,
        "wires": [
            [
                "ca2521669295ab88"
            ]
        ]
    }
]

image image

jerome6994 commented 2 years ago

Thanks for the help I even managed to embed ok i woke up at 4:00 in the morning :)

image On the other hand for the colored text it seems not possible visually on the phone but just on the app and the browser ?

jerome6994 commented 2 years ago

Good evening

I still have a usage question. Attached is my flow with the Home Assistant sensors. 4580DFF2-34B7-4186-9C68-493F47AA6F0F

What I have in discord mobile app DE981910-9392-4F66-9BF0-4FB318E67967

What i have in discord app windows 13B5EDCC-2096-49AD-992E-357E45F1B10A

To integrate the sensors in my message I use payloads with the call services But with your node the payloads do not pass! I don't have to write it right yet... Not easy to start on node red because every day is a discovery !

`const msg1 = {};

msg1.channel = "911259838544228402"; msg1.payload = "Message de Node Red"; msg.message = "msg.message" msg1.embeds = { color: '#111111', title: "Ephéméride du " & payload.date_jour & "__", description: "Description du message", author: { name: "le nom de l'auteur", icon_url: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org', }, thumbnail: { url: 'https://i.imgur.com/AfFp7pu.png', }, fields: [ { name: ":innocent: Saint du jour", value: payload.saint_jour, }, { name: ":innocent: Saint de demain", value: payload.saint_demain, inline: false, }, { name: ":sunny: Météo du jour", value: payload.meteo, inline: false, }, { name: ":sunrise: Lever du soleil__", value: payload.lever_soleil, inline: true, }, { name: ":first_quarter_moon_with_face: Coucher du soleil", value: payload.coucher_soleil, inline: true, }, ], image: { url: 'https://i.imgur.com/AfFp7pu.png', }, timestamp: new Date(), footer: { text: "Envoyé par Node-Red --- " & time, icon_url: 'https://i.imgur.com/AfFp7pu.png', }, };

return msg1; `

thanks for your help again

javis86 commented 2 years ago

I invite you to have this discussion on the discord server if you want. In the last version of the package (3.2.2), all the input message is kept in the output. The msg.payload field is used by the node, and is a pattern within Node-red use payload for the specific input parameters for the node. You can change properties to copy data outside of the msg.payload if you want. I'm gonna close the issue.