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

Function main

docpages/example_code/editing_messages2.cpp:3–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <dpp/dpp.h>
2
3int main() {
4 /* the second argument is a bitmask of intents - i_message_content is needed to get messages */
5 dpp::cluster bot("Token", dpp::i_default_intents | dpp::i_message_content);
6
7 bot.on_log(dpp::utility::cout_logger());
8
9 /* The event is fired when someone issues your commands */
10 bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
11 if (event.command.get_command_name() == "channel-edit") {
12 const auto name = std::get<std::string>(event.get_parameter("name"));
13
14 /* get the channel to edit it after */
15 const auto channel_id = std::get<dpp::snowflake>(event.get_parameter("channel"));
16 bot.channel_get(channel_id, [&bot, name, event](const dpp::confirmation_callback_t& callback) {
17 if (callback.is_error()) {
18 event.reply("error");
19 return;
20 }
21 auto channel = callback.get<dpp::channel>();
22
23 /* change the channel name and edit the channel itself */
24 channel.set_name(name);
25 bot.channel_edit(channel);
26 event.reply("Channel name is now `" + name + "`.");
27 });
28 }
29 });
30
31 bot.on_ready([&bot](const dpp::ready_t& event) {
32
33 if (dpp::run_once <struct register_global_commands>()) {
34 dpp::slashcommand channel_edit("channel-edit", "Edit the name of channel specified", bot.me.id);
35
36 channel_edit.add_option(dpp::command_option(dpp::co_channel, "channel", "Channel to edit", true));
37 channel_edit.add_option(dpp::command_option(dpp::co_string, "name", "New name for the channel", true));
38
39 bot.global_command_create(channel_edit);
40 }
41 });
42
43 bot.start(dpp::st_wait);
44 return 0;
45}

Callers

nothing calls this directly

Calls 9

cout_loggerFunction · 0.85
get_command_nameMethod · 0.80
get_parameterMethod · 0.80
channel_getMethod · 0.80
is_errorMethod · 0.80
channel_editMethod · 0.80
global_command_createMethod · 0.80
startMethod · 0.80
replyMethod · 0.45

Tested by

no test coverage detected