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

Function main

docpages/example_code/attachments2.cpp:3–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include <dpp/dpp.h>
2
3int main() {
4 dpp::cluster bot("token");
5
6 bot.on_log(dpp::utility::cout_logger());
7
8 /* The event is fired when someone issues your commands */
9 bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
10 /* Check which command they ran */
11 if (event.command.get_command_name() == "file") {
12
13 /* Request the image from the URL specified and capture the event in a lambda. */
14 bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get, [event](const dpp::http_request_completion_t & httpRequestCompletion) {
15
16 /* Create a message */
17 dpp::message msg(event.command.channel_id, "This is my new attachment:");
18
19 /* Attach the image to the message, only on success (Code 200). */
20 if (httpRequestCompletion.status == 200) {
21 msg.add_file("logo.png", httpRequestCompletion.body);
22 }
23
24 /* Send the message, with our attachment. */
25 event.reply(msg);
26 });
27 }
28 });
29
30 bot.on_ready([&bot](const dpp::ready_t& event) {
31 if (dpp::run_once<struct register_bot_commands>()) {
32 /* Create and register a command when the bot is ready */
33 bot.global_command_create(dpp::slashcommand("file", "Send a message with an image attached from the internet!", bot.me.id));
34 }
35 });
36
37 bot.start(dpp::st_wait);
38
39 return 0;
40}

Callers

nothing calls this directly

Calls 6

cout_loggerFunction · 0.85
get_command_nameMethod · 0.80
requestMethod · 0.80
global_command_createMethod · 0.80
startMethod · 0.80
replyMethod · 0.45

Tested by

no test coverage detected