| 1 | #include <dpp/dpp.h> |
| 2 | |
| 3 | int main() { |
| 4 | /* Create the bot */ |
| 5 | dpp::cluster bot("token"); |
| 6 | |
| 7 | bot.on_log(dpp::utility::cout_logger()); |
| 8 | |
| 9 | /* The event is fired when the bot detects a message in any server and any channel it has access to. */ |
| 10 | bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) { |
| 11 | /* Check which command they ran */ |
| 12 | if (event.command.get_command_name() == "create-thread") { |
| 13 | /* Here we create a thread in the current channel. It will expire after 60 minutes of inactivity. We'll also allow other mods to join, and we won't add a slowdown timer. */ |
| 14 | bot.thread_create("Cool thread!", event.command.channel_id, 60, dpp::channel_type::CHANNEL_PUBLIC_THREAD, true, 0, [event](const dpp::confirmation_callback_t& callback) { |
| 15 | if (callback.is_error()) { |
| 16 | event.reply("Failed to create a thread!"); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | event.reply("Created a thread for you!"); |
| 21 | }); |
| 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 the command */ |
| 28 | bot.global_command_create(dpp::slashcommand("create-thread", "Create a thread!", bot.me.id)); |
| 29 | } |
| 30 | }); |
| 31 | |
| 32 | bot.start(dpp::st_wait); |
| 33 | |
| 34 | return 0; |
| 35 | } |