Skip to content

Commit

Permalink
docs: changed making_threads.md to include more info (#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 authored Oct 9, 2023
1 parent 1bca602 commit 2d11c8f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
50 changes: 50 additions & 0 deletions docpages/example_code/making_threads3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <dpp/dpp.h>

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<dpp::thread>();

/* 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<struct register_bot_commands>()) {
/* 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;
}
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
\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
Binary file added docpages/images/creating_thread_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2d11c8f

Please sign in to comment.