| 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 | dpp::message msg(event.command.channel_id, "Hey there, I've got a new file!"); |
| 13 | |
| 14 | /* attach the file to the message */ |
| 15 | msg.add_file("foobar.txt", dpp::utility::read_file("path_to_your_file.txt")); |
| 16 | |
| 17 | /* Reply to the user with the message, with our file attached. */ |
| 18 | event.reply(msg); |
| 19 | } |
| 20 | }); |
| 21 | |
| 22 | bot.on_ready([&bot](const dpp::ready_t& event) { |
| 23 | if (dpp::run_once<struct register_bot_commands>()) { |
| 24 | /* Create and register a command when the bot is ready */ |
| 25 | bot.global_command_create(dpp::slashcommand("file", "Send a message with a file attached!", bot.me.id)); |
| 26 | } |
| 27 | }); |
| 28 | |
| 29 | bot.start(dpp::st_wait); |
| 30 | |
| 31 | return 0; |
| 32 | } |