Debian Codegraph @

docpages/example_code/coro_intro.cpp

raw symbols SCIP
1 #include <dpp/dpp.h>
2
3 int main() {
4 dpp::cluster bot{"token"};
5
6 bot.on_log(dpp::utility::cout_logger());
7
8 /* The event is fired when someone issues your commands */
9 bot.on_slashcommand([](const dpp::slashcommand_t& event) -> dpp::task<void> {
10 if (event.command.get_command_name() == "file") {
11 /* Request the image from the URL specified and co_await the response */
12 dpp::http_request_completion_t result = co_await event.owner->co_request("https://dpp.dev/DPP-Logo.png", dpp::m_get);
13
14 /* Create a message and attach the image on success */
15 dpp::message msg(event.command.channel_id, "This is my new attachment:");
16 if (result.status == 200) {
17 msg.add_file("logo.png", result.body);
18 }
19
20 /* Send the message, with our attachment. */
21 event.reply(msg);
22 }
23 });
24
25 bot.on_ready([&bot](const dpp::ready_t& event) {
26 if (dpp::run_once<struct register_bot_commands>()) {
27 /* Create and register a command when the bot is ready */
28 bot.global_command_create(dpp::slashcommand{"file", "Send a message with an image attached from the internet!", bot.me.id});
29 }
30 });
31
32 bot.start(dpp::st_wait);
33
34 return 0;
35 }