| 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() == "show") { |
| 12 | /* Get the file id from the parameter attachment. */ |
| 13 | dpp::snowflake file_id = std::get<dpp::snowflake>(event.get_parameter("file")); |
| 14 | |
| 15 | /* Get the attachment that the user inputted from the file id. */ |
| 16 | dpp::attachment att = event.command.get_resolved_attachment(file_id); |
| 17 | |
| 18 | /* Reply with the file as a URL. */ |
| 19 | event.reply(att.url); |
| 20 | } |
| 21 | }); |
| 22 | |
| 23 | bot.on_ready([&bot](const dpp::ready_t& event) { |
| 24 | if (dpp::run_once<struct register_bot_commands>()) { |
| 25 | /* Create a new command. */ |
| 26 | dpp::slashcommand newcommand("show", "Show an uploaded file", bot.me.id); |
| 27 | |
| 28 | /* Add a parameter option. */ |
| 29 | newcommand.add_option(dpp::command_option(dpp::co_attachment, "file", "Select an image")); |
| 30 | |
| 31 | /* Register the command */ |
| 32 | bot.global_command_create(newcommand); |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | bot.start(dpp::st_wait); |
| 37 | |
| 38 | return 0; |
| 39 | } |