To attach a local file to an message, you can use dpp::utility::read_file. It's a helper function from D++ that allows you to read the file's content and sent it to discord.
An example of this:
#include <dpp/dpp.h>
int main() {
event.reply(msg);
}
});
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:89
snowflake channel_id
Optional: the channel it was sent from.
Definition appcommand.h:1043
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:1436
std::string DPP_EXPORT read_file(const std::string &filename)
Read a whole file into a std::string.
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
auto run_once()
Run some code within an if() statement only once.
Definition once.h:41
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition cluster.h:72
interaction command
command interaction
Definition dispatcher.h:789
Represents messages sent and received on Discord.
Definition message.h:2350
Session ready.
Definition dispatcher.h:1072
User has issued a slash command.
Definition dispatcher.h:806
Attachments via URL aren't possible. But there's a workaround for this! You can download the file and then attach it to the message.
Amazingly, D++ also has a function for this! You can use dpp::cluster::request to make HTTP requests, allowing you to go ahead and pull the content from a URL.
The following example program shows how to request a file and attach it to a message:
#include <dpp/dpp.h>
int main() {
if (httpRequestCompletion.
status == 200) {
msg.add_file(
"logo.png", httpRequestCompletion.
body);
}
event.reply(msg);
});
}
});
bot.global_command_create(
dpp::slashcommand(
"file",
"Send a message with an image attached from the internet!", bot.me.id));
}
});
return 0;
}
@ m_get
GET.
Definition queues.h:189
The result of any HTTP request. Contains the headers, vital rate limit figures, and returned request ...
Definition queues.h:111
uint16_t status
HTTP status. e.g. 200 = OK, 404 = Not found, 429 = Rate limited, etc.
Definition queues.h:121
std::string body
Reply body.
Definition queues.h:162
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() {
msg.add_embed(embed);
event.reply(msg);
}
});
bot.global_command_create(
dpp::slashcommand(
"file",
"Send a local image along with an embed with the image!", bot.me.id));
}
});
return 0;
}
A rich embed for display within a dpp::message.
Definition message.h:1090
embed & set_image(std::string_view url)
Set embed image.