MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / main

Function main

docpages/example_code/making_threads3.cpp:3–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <dpp/dpp.h>
2
3int 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() == "lock-thread") {
13 /* Get this channel as a thread. */
14 bot.thread_get(event.command.channel_id, [&bot, event](const dpp::confirmation_callback_t& callback) {
15 if (callback.is_error()) {
16 event.reply("I failed to get the thread!");
17 return;
18 }
19
20 /* Get the thread from the callback. */
21 auto thread = callback.get<dpp::thread>();
22
23 /* Set the thread to locked. */
24 thread.metadata.locked = true;
25
26 /* Now we tell discord about our updates, meaning the thread will lock! */
27 bot.thread_edit(thread, [event](const dpp::confirmation_callback_t& callback2) {
28 if (callback2.is_error()) {
29 event.reply("I failed to lock the thread!");
30 return;
31 }
32
33 event.reply("I have locked the thread!");
34 });
35 });
36 }
37 });
38
39 bot.on_ready([&bot](const dpp::ready_t& event) {
40 if (dpp::run_once<struct register_bot_commands>()) {
41 /* Create and register the command */
42 bot.global_command_create(dpp::slashcommand("lock-thread", "Lock the thread that you run this command in!", bot.me.id));
43 }
44 });
45
46 bot.start(dpp::st_wait);
47
48 return 0;
49}

Callers

nothing calls this directly

Calls 8

cout_loggerFunction · 0.85
get_command_nameMethod · 0.80
thread_getMethod · 0.80
is_errorMethod · 0.80
thread_editMethod · 0.80
global_command_createMethod · 0.80
startMethod · 0.80
replyMethod · 0.45

Tested by

no test coverage detected