| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
Sending Embeds

If you've been in a server and used a bot or even seen a message from a bot, you might have seen a special message type, often sent by these bots. These are called embeds! In this section, we will show how to create an embed and reply to a user, using our newly created embed!

#include <dpp/dpp.h>
int main() {
/* Setup the bot */
dpp::cluster bot("token");
bot.on_log(dpp::utility::cout_logger());
/* The event is fired when someone issues your commands */
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "embed") {
/* Create an embed */
dpp::embed embed = dpp::embed()
.set_color(dpp::colors::sti_blue)
.set_title("Some name")
.set_url("https://dpp.dev/")
.set_author("Some name", "https://dpp.dev/", "https://dpp.dev/DPP-Logo.png")
.set_description("Some description here")
.set_thumbnail("https://dpp.dev/DPP-Logo.png")
.add_field(
"Regular field title",
"Some value here"
)
.add_field(
"Inline field title",
"Some value here",
true
)
.add_field(
"Inline field title",
"Some value here",
true
)
.set_image("https://dpp.dev/DPP-Logo.png")
.set_footer(
dpp::embed_footer()
.set_text("Some footer text here")
.set_icon("https://dpp.dev/DPP-Logo.png")
)
.set_timestamp(time(0));
/* Create a message with the content as our new embed. */
dpp::message msg(event.command.channel_id, embed);
/* Reply to the user with the message, containing our embed. */
event.reply(msg);
}
});
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create and register a command when the bot is ready */
bot.global_command_create(dpp::slashcommand("embed", "Send a test embed!", bot.me.id));
}
});
bot.start(dpp::st_wait);
return 0;
}
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition cluster.h:89
dpp::interaction::channel_id
snowflake channel_id
Optional: the channel it was sent from.
Definition appcommand.h:1043
dpp::interaction::get_command_name
std::string get_command_name() const
Get the command name for a command interaction.
dpp::slashcommand
Represents an application command, created by your bot either globally, or on a guild.
Definition appcommand.h:1436
dpp::colors::sti_blue
static constexpr uint32_t sti_blue
Definition colors.h:70
dpp::utility::cout_logger
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
dpp::run_once
auto run_once()
Run some code within an if() statement only once.
Definition once.h:41
dpp::st_wait
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition cluster.h:72
dpp::embed
A rich embed for display within a dpp::message.
Definition message.h:1090
dpp::embed::set_description
embed & set_description(std::string_view text)
Set embed description.
dpp::embed::set_author
embed & set_author(const dpp::embed_author &a)
Set embed author.
dpp::embed::set_image
embed & set_image(std::string_view url)
Set embed image.
dpp::embed::set_color
embed & set_color(uint32_t col)
Set embed colour.
dpp::embed::set_title
embed & set_title(std::string_view text)
Set embed title.
dpp::embed::set_timestamp
embed & set_timestamp(time_t tstamp)
Set embed timestamp.
dpp::embed::set_thumbnail
embed & set_thumbnail(std::string_view url)
Set embed thumbnail.
dpp::embed::set_url
embed & set_url(std::string_view url)
Set embed url.
dpp::embed::add_field
embed & add_field(std::string_view name, std::string_view value, bool is_inline=false)
Add an embed field.
dpp::embed::set_footer
embed & set_footer(const embed_footer &f)
Set the footer of the embed.
dpp::interaction_create_t::command
interaction command
command interaction
Definition dispatcher.h:789
dpp::message
Represents messages sent and received on Discord.
Definition message.h:2350
dpp::ready_t
Session ready.
Definition dispatcher.h:1072
dpp::slashcommand_t
User has issued a slash command.
Definition dispatcher.h:806

The code will send the following message.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0