diff --git a/docpages/example_code/making_threads3.cpp b/docpages/example_code/making_threads3.cpp new file mode 100644 index 0000000000..db5464ba6f --- /dev/null +++ b/docpages/example_code/making_threads3.cpp @@ -0,0 +1,50 @@ +#include + +int main() +{ + /* Create the bot */ + dpp::cluster bot("token"); + + 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) { + /* Check which command they ran */ + if (event.command.get_command_name() == "lock-thread") { + /* Get this channel as a thread. */ + bot.thread_get(event.command.channel_id, [&bot, event](const dpp::confirmation_callback_t& callback) { + if (callback.is_error()) { + event.reply("I failed to get the thread!"); + return; + } + + /* Get the thread from the callback. */ + auto thread = callback.get(); + + /* Set the thread to locked. */ + thread.metadata.locked = true; + + /* Now we tell discord about our updates, meaning the thread will lock! */ + bot.thread_edit(thread, [event](const dpp::confirmation_callback_t& callback2) { + if (callback2.is_error()) { + event.reply("I failed to lock the thread!"); + return; + } + + event.reply("I have locked the thread!"); + }); + }); + } + }); + + bot.on_ready([&bot](const dpp::ready_t& event) { + if (dpp::run_once()) { + /* Create and register the command */ + bot.global_command_create(dpp::slashcommand("lock-thread", "Lock the thread that you run this command in!", bot.me.id)); + } + }); + + bot.start(dpp::st_wait); + + return 0; +} \ No newline at end of file diff --git a/docpages/example_programs/interactions_and_components/making_threads.md b/docpages/example_programs/interactions_and_components/making_threads.md index ee24e614d6..c207cbf91c 100644 --- a/docpages/example_programs/interactions_and_components/making_threads.md +++ b/docpages/example_programs/interactions_and_components/making_threads.md @@ -1,8 +1,12 @@ -\page making_threads Creating and talking in a thread +\page making_threads Creating and interacting with threads A new feature added to Discord recently is `Threads`, these allow you to break off a message into a different "channel", without creating a whole new channel. There are also other types of "thread channels", one example being a `forums channel`. This type of channel only contains threads, meaning you can't send messages in it so if you want to make one of them, be careful about trying to send a message in it! -In this tutorial, we'll be going through how to create a thread and how to talk in a thread. +In this tutorial, we'll be going through: + +- How to create a thread. +- How to loop through all the active threads in a server (and sending a message in one). +- How to lock a thread (editing threads). First, let's go through creating a thread. @@ -12,10 +16,20 @@ 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. It's worth noting that we will be assuming that the thread you just created is the only thread in your server! +Now, let's cover looping through all the threads in a server. For this demonstration, we'll be picking the first thread we find in the list and sending a message in it. \include{cpp} making_threads2.cpp After that, you'll be able to see your bot send a message in your thread! -\image html creating_thread_2.png \ No newline at end of file +\image html creating_thread_2.png + +Those of you who are familar with sending messages in regular channels may have also noticed that sending messages to threads is the same as sending a general message. This is because threads are basically channels with a couple more features! + +Now, we're going to cover how to lock a thread! With this, you'll also learn how to edit threads in general, meaning you can go forward and learn how to change even more stuff about threads, as much as your heart desires! + +\include{cpp} making_threads3.cpp + +Once you've ran that, you'll see that you were successfully able to lock a thread! + +\image html creating_thread_3.png \ No newline at end of file diff --git a/docpages/images/creating_thread_3.png b/docpages/images/creating_thread_3.png new file mode 100644 index 0000000000..eaf6b3376e Binary files /dev/null and b/docpages/images/creating_thread_3.png differ