Attached files must be locally stored.
To attach a file to a message, you can upload a local image.
D++ has this helper function to read a file: dpp::utility::read_file.
An example program:
#include <dpp/dpp.h>
int main() {
dpp::message msg(event.command.channel_id, "Hey there, I've got a new file!");
msg.add_file("foobar.txt", dpp::utility::read_file("path_to_your_file.txt"));
event.reply(msg);
}
});
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand(
"file",
"Send a message with a file attached!", bot.me.id));
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:80
std::string get_command_name() const
Get the command name for a command interaction.
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:1136
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:63
interaction command
command interaction
Definition: dispatcher.h:644
Session ready.
Definition: dispatcher.h:908
User has issued a slash command.
Definition: dispatcher.h:661
Attachments via an url aren't possible. But there's a workaround for. You can download the file and then attach it to the message.
To make requests, D++ also has a helper function: dpp::cluster::request.
The following example program shows how to request a file and attach it to a message.
#include <dpp/dpp.h>
int main() {
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get, [event](const dpp::http_request_completion_t & httpRequestCompletion) {
dpp::message msg(event.command.channel_id, "This is my new attachment:");
if (httpRequestCompletion.status == 200) {
msg.add_file("logo.png", httpRequestCompletion.body);
}
event.reply(msg);
});
}
});
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand(
"file",
"Send a message with an image attached from the internet!", bot.me.id));
}
});
return 0;
}
Here's another example of how to add a local image to an embed.
Upload the image in the same message as the embed and then reference it in the embed.
#include <dpp/dpp.h>
int main() {
dpp::message msg(event.command.channel_id, "");
msg.add_file("image.jpg", dpp::utility::read_file("path_to_your_image.jpg"));
dpp::embed embed;
embed.set_image("attachment://image.jpg");
msg.add_embed(embed);
event.reply(msg);
}
});
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand(
"file",
"Send a local image along with an embed with the image!", bot.me.id));
}
});
return 0;
}