Help Help With Cleo [Discord Webhooks Embeds]

Saam

Active member
Joined
Apr 18, 2021
Messages
112
Reaction score
62
Location
Argentina
Hello, I was following this example to make discord http requests to a webhook, the problem is that when trying to include the embeds (description and color) cleo gives this error:
JavaScript:
Respuesta = {"embeds": ["Only iterables may be used in a ListType"]}
Data:
Code:
"content=testing message&username=custom_username&embeds=description=test"
How can i fix it?
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,126
Solutions
1
Reaction score
158
I think it would be good idea to first get it work using python/curl or whatever request sending program, and only after it works attempt to do the same in cleo. You could use chatgpt to write examples, it produced some when I asked for them:
 

Saam

Active member
Joined
Apr 18, 2021
Messages
112
Reaction score
62
Location
Argentina
I think it would be good idea to first get it work using python/curl or whatever request sending program, and only after it works attempt to do the same in cleo. You could use chatgpt to write examples, it produced some when I asked for them:
Example with CURL (C++)
C++:
int http_request(std::string_view url, const std::string& payload) {
    CURL* curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_ALL);
    curl = curl_easy_init();

    if (curl) {
        struct curl_slist* headers = nullptr;
        headers = curl_slist_append(headers, "Content-Type: application/json");
        curl_easy_setopt(curl, CURLOPT_URL, url.data());
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload.data());
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

        res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            AddChatMessage(curl_easy_strerror(res), 0xFFFFFFFF);
        }

        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();
    return 0;
}

void SendHook()
{
    std::string webhookUrl = "https://discord.com/api/webhooks/id/token";
    std::string description = "Testing:";
    std::string payload = R"({
    "username": "Test Webhook",
    "avatar_url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7eXeizKfnjW1UG4T1wnB2cXv4x2wf8Vtr7kcSpby_wrtsTAt0EN-aoMjgaIsmyrBpHaY&usqp=CAU",
    "embeds": [{
        "description": ")" + description + R"(",
        "color": 16711680
    }]})";
   http_request(webhookUrl, payload);
}
 
Top