| 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([&bot](const dpp::slashcommand_t& event) { |
| 10 | /* Check which command they ran */ |
| 11 | if (event.command.get_command_name() == "file") { |
| 12 | |
| 13 | /* Request the image from the URL specified and capture the event in a lambda. */ |
| 14 | bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get, [event](const dpp::http_request_completion_t & httpRequestCompletion) { |
| 15 | |
| 16 | /* Create a message */ |
| 17 | dpp::message msg(event.command.channel_id, "This is my new attachment:"); |
| 18 | |
| 19 | /* Attach the image to the message, only on success (Code 200). */ |
| 20 | if (httpRequestCompletion.status == 200) { |
| 21 | msg.add_file("logo.png", httpRequestCompletion.body); |
| 22 | } |
| 23 | |
| 24 | /* Send the message, with our attachment. */ |
| 25 | event.reply(msg); |
| 26 | }); |
| 27 | } |
| 28 | }); |
| 29 | |
| 30 | bot.on_ready([&bot](const dpp::ready_t& event) { |
| 31 | if (dpp::run_once<struct register_bot_commands>()) { |
| 32 | /* Create and register a command when the bot is ready */ |
| 33 | bot.global_command_create(dpp::slashcommand("file", "Send a message with an image attached from the internet!", bot.me.id)); |
| 34 | } |
| 35 | }); |
| 36 | |
| 37 | bot.start(dpp::st_wait); |
| 38 | |
| 39 | return 0; |
| 40 | } |
nothing calls this directly
no test coverage detected