From b143703c46d018ba4d37215ad858a51d919f621d Mon Sep 17 00:00:00 2001 From: Jaskowicz1 Date: Sat, 9 Sep 2023 19:49:06 +0100 Subject: [PATCH] docs: fixed up documentation --- .../making_threads.md | 75 ++++++++++--------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/docpages/example_programs/interactions_and_components/making_threads.md b/docpages/example_programs/interactions_and_components/making_threads.md index 1011b708be..f6833a7a29 100644 --- a/docpages/example_programs/interactions_and_components/making_threads.md +++ b/docpages/example_programs/interactions_and_components/making_threads.md @@ -10,34 +10,37 @@ First, let's go through creating a thread. int main() { - /* Create the bot */ - dpp::cluster bot("token"); + /* Create the bot */ + dpp::cluster bot("token"); - bot.on_log(dpp::utility::cout_logger()); + bot.on_log(dpp::utility::cout_logger()); - /* The event is fired when the bot detects a message in any server and any channel it has access to. */ - bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) { + /* The event is fired when the bot detects a message in any server and any channel it has access to. */ + bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) { /* Check which command they ran */ if (event.command.get_command_name() == "create-thread") { /* 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. */ - BUDe::botRef->thread_create("Cool thread!", event.command.channel_id, 60, dpp::channel_type::CHANNEL_PUBLIC_THREAD, true, 0); - - /* As always, we need to reply so the interaction doesn't fail! */ - event.reply("Created a thread for you!"); - + 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) { + if(callback.is_error()) { + event.reply("Failed to create a thread!"); + return; + } + + event.reply("Created a thread for you!"); + }); } - }); - - bot.on_ready([&bot](const dpp::ready_t& event) { + }); + + bot.on_ready([&bot](const dpp::ready_t& event) { if (dpp::run_once()) { /* Create and register the command */ bot.global_command_create(dpp::slashcommand("create-thread", "Create a thread!", bot.me.id)); } - }); + }); - bot.start(dpp::st_wait); + bot.start(dpp::st_wait); - return 0; + return 0; } ~~~~~~~~~~ @@ -45,44 +48,42 @@ If all went well, you'll see that the bot has successfully created a thread! \image html creating_thread.png -Now, let's cover talking in that thread from a channel. - +Now, let's cover talking in that thread from a channel. It's worth noting that we will be assuming that the thread you just created is the only thread in your server! ~~~~~~~~~~{.cpp} #include int main() { - /* Create the bot */ - dpp::cluster bot("token"); + /* Create the bot */ + dpp::cluster bot("token"); - bot.on_log(dpp::utility::cout_logger()); + bot.on_log(dpp::utility::cout_logger()); - /* The event is fired when the bot detects a message in any server and any channel it has access to. */ - bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) { + /* The event is fired when the bot detects a message in any server and any channel it has access to. */ + bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) { /* Check which command they ran */ if (event.command.get_command_name() == "message-thread") { /* Get all active threads in a guild. */ bot.threads_get_active(event.command.guild_id, [&bot, event](const dpp::confirmation_callback_t& callback) { - if(callback.is_error()) { event.reply("Failed to get threads!"); return; } - + /* Get the list of active threads in the guild. */ auto threads = callback.get(); - + dpp::snowflake thread_id; - + /* Loop through the threads, getting each value in the map. Then we get the first value and then break off. - * The reason we're getting only the first value is because, for this example, we'll just assume you've only got a single active thread (the one created by the bot) - */ + * The reason we're getting only the first value is because, for this example, we'll just assume you've only got a single active thread (the one created by the bot) + */ for(const auto& _thread : threads) { thread_id = _thread.first; break; } - + /* Send a message in the first thread we find. */ bot.message_create(dpp::message(thread_id, "Hey, I'm first to message in a cool thread!"), [event](const dpp::confirmation_callback_t& callback2) { if(callback2.is_error()) { @@ -90,22 +91,22 @@ int main() return; } - event.reply("I've sent a message in the specified thread."); + event.reply("I've sent a message in the specified thread."); }); }); } - }); - - bot.on_ready([&bot](const dpp::ready_t& event) { + }); + + bot.on_ready([&bot](const dpp::ready_t& event) { if (dpp::run_once()) { /* Create and register the command */ bot.global_command_create(dpp::slashcommand("message-thread", "Message a thread!", bot.me.id)); } - }); + }); - bot.start(dpp::st_wait); + bot.start(dpp::st_wait); - return 0; + return 0; } ~~~~~~~~~~