-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: changed making_threads.md to include more info (#932)
- Loading branch information
1 parent
1bca602
commit 2d11c8f
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.