| 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) { |
| 10 | /* Check which command they ran */ |
| 11 | if (event.command.get_command_name() == "file") { |
| 12 | /* Create a message. */ |
| 13 | dpp::message msg(event.command.channel_id, ""); |
| 14 | |
| 15 | /* Attach the image to the message we just created. */ |
| 16 | msg.add_file("image.jpg", dpp::utility::read_file("path_to_your_image.jpg")); |
| 17 | |
| 18 | /* Create an embed. */ |
| 19 | dpp::embed embed; |
| 20 | embed.set_image("attachment://image.jpg"); /* Set the image of the embed to the attached image. */ |
| 21 | |
| 22 | /* Add the embed to the message. */ |
| 23 | msg.add_embed(embed); |
| 24 | |
| 25 | event.reply(msg); |
| 26 | } |
| 27 | }); |
| 28 | |
| 29 | bot.on_ready([&bot](const dpp::ready_t& event) { |
| 30 | if (dpp::run_once<struct register_bot_commands>()) { |
| 31 | /* Create and register a command when the bot is ready */ |
| 32 | bot.global_command_create(dpp::slashcommand("file", "Send a local image along with an embed with the image!", bot.me.id)); |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | bot.start(dpp::st_wait); |
| 37 | |
| 38 | return 0; |
| 39 | } |