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

Function main

docpages/example_code/making_threads2.cpp:3–56  ·  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() == "message-thread") {
13 /* Get all active threads in a guild. */
14 bot.threads_get_active(event.command.guild_id, [&bot, event](const dpp::confirmation_callback_t& callback) {
15 if (callback.is_error()) {
16 event.reply("Failed to get threads!");
17 return;
18 }
19
20 /* Get the list of active threads in the guild. */
21 auto threads = callback.get<dpp::active_threads>();
22
23 dpp::snowflake thread_id;
24
25 /* Loop through the threads, getting each value in the map. Then we get the first value and then break off.
26 * 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)
27 */
28 for (const auto& _thread : threads) {
29 thread_id = _thread.first;
30 break;
31 }
32
33 /* Send a message in the first thread we find. */
34 bot.message_create(dpp::message(thread_id, "Hey, I'm first to message in a cool thread!"), [event](const dpp::confirmation_callback_t& callback2) {
35 if (callback2.is_error()) {
36 event.reply("Failed to send a message in a thread.");
37 return;
38 }
39
40 event.reply("I've sent a message in the specified thread.");
41 });
42 });
43 }
44 });
45
46 bot.on_ready([&bot](const dpp::ready_t& event) {
47 if (dpp::run_once<struct register_bot_commands>()) {
48 /* Create and register the command */
49 bot.global_command_create(dpp::slashcommand("message-thread", "Message a thread!", bot.me.id));
50 }
51 });
52
53 bot.start(dpp::st_wait);
54
55 return 0;
56}

Callers

nothing calls this directly

Calls 9

cout_loggerFunction · 0.85
get_command_nameMethod · 0.80
threads_get_activeMethod · 0.80
is_errorMethod · 0.80
message_createMethod · 0.80
global_command_createMethod · 0.80
startMethod · 0.80
messageClass · 0.50
replyMethod · 0.45

Tested by

no test coverage detected