Attached files must be locally stored.
To attach a file to a message, you can upload a local image.
D++ has this helper function to read a file: dpp::utility::read_file
.
An example program:
#include <dpp/dpp.h>
#include <filesystem>
int main() {
dpp::message msg(event.msg.channel_id, "Hey there, i've got a new image!");
std::filesystem::path filePath("path_to_your_file.json");
msg.set_file_content(dpp::utility::read_file(filePath.relative_path()));
msg.set_filename(filePath.filename());
bot.message_create(msg);
}
});
bot.start(false);
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:373
Create message.
Definition: dispatcher.h:1122
message msg
message that was created (sent).
Definition: dispatcher.h:1131
std::string content
Definition: message.h:964
Attachments via an url aren't possible. But there's a workaround for. You can download the file and then attach it to the message.
To make requests, D++ also has a helper function: dpp::cluster::request
.
The following example program shows how to request a file and attach it to a message.
#include <dpp/dpp.h>
int main() {
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get, [&bot, channel_id = event.msg.channel_id](const dpp::http_request_completion_t & httpRequestCompletion) {
dpp::message msg(channel_id, "This is my new attachment:");
if (httpRequestCompletion.status == 200) {
msg.set_file_content(httpRequestCompletion.body);
msg.set_filename("example-image.png");
}
bot.message_create(msg);
});
}
});
bot.start(false);
return 0;
}