Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docpages/example_code/attachments1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "file") {
dpp::message msg(event.command.channel_id, "Hey there, I've got a new file!");
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/attachments2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main() {
if (event.command.get_command_name() == "file") {

/* Request the image from the URL specified and capture the event in a lambda. */
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get, [event](const dpp::http_request_completion_t & httpRequestCompletion) {
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get, [event](const dpp::http_request_completion_t& httpRequestCompletion) {

/* Create a message */
dpp::message msg(event.command.channel_id, "This is my new attachment:");
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/attachments3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "file") {
/* Create a message. */
Expand Down
6 changes: 3 additions & 3 deletions docpages/example_code/autocomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main()

bot.on_log(dpp::utility::cout_logger());

bot.on_ready([&bot](const dpp::ready_t & event) {
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {

/* Create a new global command once on ready event */
Expand All @@ -23,7 +23,7 @@ int main()
});

/* The interaction create event is fired when someone issues your commands */
bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {

/* Check which command they ran */
if (event.command.get_command_name() == "blep") {
Expand All @@ -39,7 +39,7 @@ int main()
/* The on_autocomplete event is fired whenever discord needs information to fill in a command options's choices.
* You must reply with a REST event within 500ms, so make it snappy!
*/
bot.on_autocomplete([&bot](const dpp::autocomplete_t & event) {
bot.on_autocomplete([&bot](const dpp::autocomplete_t& event) {
for (auto & opt : event.options) {
/* The option which has focused set to true is the one the user is typing in */
if (opt.focused) {
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/cache_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main() {
bot.on_log(dpp::utility::cout_logger());

/* Message handler */
bot.on_message_create([&message_cache](const dpp::message_create_t &event) {
bot.on_message_create([&message_cache](const dpp::message_create_t& event) {
/* Make a permanent pointer using new, for each message to be cached */
dpp::message* m = new dpp::message();

Expand All @@ -23,7 +23,7 @@ int main() {
});

/* The event is fired when someone issues your commands */
bot.on_slashcommand([&bot, &message_cache](const dpp::slashcommand_t& event) {
bot.on_slashcommand([&message_cache](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "get") {

Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/clearing_slashcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {

/* We won't be performing any commands, so we don't need to add the event here! */

bot.on_ready([&bot](const dpp::ready_t & event) {
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct clear_bot_commands>()) {
/* Now, we're going to wipe our commands */
bot.global_bulk_command_delete();
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/commandhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main() {
command_handler.add_prefix(".")
.add_prefix("/");

bot.on_ready([&command_handler](const dpp::ready_t &event) {
bot.on_ready([&command_handler](const dpp::ready_t& event) {

command_handler.add_command(
/* Command name */
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "button") {
/* Create a message */
Expand All @@ -33,7 +33,7 @@ int main() {
/* When a user clicks your button, the on_button_click event will fire,
* containing the custom_id you defined in your button.
*/
bot.on_button_click([&bot](const dpp::button_click_t& event) {
bot.on_button_click([](const dpp::button_click_t& event) {
/* Button clicks are still interactions, and must be replied to in some form to
* prevent the "this interaction has failed" message from Discord to the user.
*/
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/components2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "math") {

Expand Down Expand Up @@ -40,7 +40,7 @@ int main() {
}
});

bot.on_button_click([&bot](const dpp::button_click_t & event) {
bot.on_button_click([](const dpp::button_click_t& event) {
if (event.custom_id == "10") {
event.reply(dpp::message("You got it right!").set_flags(dpp::m_ephemeral));
} else {
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/components3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "select") {
/* Create a message */
Expand All @@ -33,7 +33,7 @@ int main() {
/* When a user clicks your select menu , the on_select_click event will fire,
* containing the custom_id you defined in your select menu.
*/
bot.on_select_click([&bot](const dpp::select_click_t & event) {
bot.on_select_click([](const dpp::select_click_t& event) {
/* Select clicks are still interactions, and must be replied to in some form to
* prevent the "this interaction has failed" message from Discord to the user.
*/
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/components3_rolemenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "select") {
/* Create a message */
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/context_menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main()
}
});

bot.on_ready([&bot](const dpp::ready_t &event) {
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create the command */
dpp::slashcommand command;
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/coro_expiring_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ int main() {
co_await event.co_reply(m);

auto result = co_await dpp::when_any{ // Whichever completes first...
event.owner->on_button_click.when([&id](const dpp::button_click_t &b) { // Button clicked
event.owner->on_button_click.when([&id](const dpp::button_click_t& b) { // Button clicked
return b.custom_id == id;
}),
event.owner->co_sleep(5) // Or sleep 5 seconds
};
// Note!! Due to a bug in g++11 and g++12, id must be captured as a reference above or the compiler will destroy it twice. This is fixed in g++13
if (result.index() == 0) { // Awaitable #0 completed first, that is the button click event
// Acknowledge the click and edit the original response, removing the button
const dpp::button_click_t &click_event = result.get<0>();
const dpp::button_click_t& click_event = result.get<0>();
click_event.reply();
event.edit_original_response(dpp::message{"You clicked the button with the id " + click_event.custom_id});
} else { // Here index() is 1, the timer expired
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/coro_simple_commands2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {
bot.on_slashcommand([](const dpp::slashcommand_t& event) -> dpp::task<void> {
if (event.command.get_command_name() == "avatar") {
// Make a nested coroutine to fetch the guild member requested, that returns it as an optional
constexpr auto resolve_member = [](const dpp::slashcommand_t &event) -> dpp::task<std::optional<dpp::guild_member>> {
constexpr auto resolve_member = [](const dpp::slashcommand_t& event) -> dpp::task<std::optional<dpp::guild_member>> {
const dpp::command_value &user_param = event.get_parameter("user");
dpp::snowflake user_id;
if (std::holds_alternative<std::monostate>(user_param)) {
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/default_select_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "select") {
/* Create a message */
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/detecting_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
bot.on_log(dpp::utility::cout_logger());

/* The event is fired when the bot detects a message in any server and any channel it has access to. */
bot.on_message_create([&bot](const dpp::message_create_t& event) {
bot.on_message_create([](const dpp::message_create_t& event) {
/* See if the message contains the phrase we want to check for.
* If there's at least a single match, we reply and say it's not allowed.
*/
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/editing_message_after_click.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "button") {
/* Create a message */
Expand All @@ -33,7 +33,7 @@ int main() {
/* When a user clicks your button, the on_button_click event will fire,
* containing the custom_id you defined in your button.
*/
bot.on_button_click([&bot](const dpp::button_click_t& event) {
bot.on_button_click([](const dpp::button_click_t& event) {
/* Instead of replying to the button click itself,
* we want to update the message that had the buttons on it.
*/
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/editing_message_after_click2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "button") {
/* Create a message */
Expand All @@ -33,7 +33,7 @@ int main() {
/* When a user clicks your button, the on_button_click event will fire,
* containing the custom_id you defined in your button.
*/
bot.on_button_click([&bot](const dpp::button_click_t& event) {
bot.on_button_click([](const dpp::button_click_t& event) {
/* Instead of replying to the button click itself,
* we want to update the message that had the buttons on it.
*/
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/embeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "embed") {
/* Create an embed */
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/ephemeral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "hello") {
/* Reply to the user, but only let them see the response. */
event.reply(dpp::message("Hello! How are you today?").set_flags(dpp::m_ephemeral));
}
});

bot.on_ready([&bot](const dpp::ready_t & event) {
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create and Register the command */
bot.global_command_create(dpp::slashcommand("hello", "Hello there!", bot.me.id));
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int main() {
* This code assumes the current directory is writeable. The file will have a
* unique name made from the user's id and the message id.
*/
std::string source_filename = std::to_string(event.msg.author.id) + "_" + std::to_string(event.msg.id) + ".cpp";
std::string source_filename = std::to_string(event.msg.author.id) + "_" + std::to_string(event.msg.id) + ".cpp";
std::fstream code_file(source_filename, std::fstream::binary | std::fstream::out);
if (!code_file.is_open()) {
bot.message_create(dpp::message(event.msg.channel_id, "Unable to create source file for `eval`"));
Expand All @@ -96,7 +96,7 @@ int main() {
std::to_string(event.msg.author.id) + "_" + std::to_string(event.msg.id) + ".cpp",
"-ldpp",
"-ldl"
}, [event, &bot, source_filename, compile_start](const std::string &output) {
}, [event, &bot, compile_start](const std::string &output) {

/* After g++ is ran we end up inside this lambda with the output as a string */
double compile_time = dpp::utility::time_f() - compile_start;
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* This is the snowflake ID of the bot's developer.
* The eval command will be restricted to this user.
*/
#define MY_DEVELOPER 189759562910400512ULL
constexpr unsigned long long MY_DEVELOPER = 189759562910400512ULL;

/* Any functions you want to be usable from within an eval,
* that are not part of D++ itself or the message event, you
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int main() {
std::string mypostdata = "{\"value\": 42}";
// Make a HTTP POST request. HTTP and HTTPS are supported here.
bot.request(
"http://www.somebotlist.com/api/servers", dpp::m_post, [](const dpp::http_request_completion_t & cc) {
"http://www.somebotlist.com/api/servers", dpp::m_post, [](const dpp::http_request_completion_t& cc) {
// This callback is called when the HTTP request completes. See documentation of
// dpp::http_request_completion_t for information on the fields in the parameter.
std::cout << "I got reply: " << cc.body << " with HTTP status code: " << cc.status << "\n";
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/join_voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main() {
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) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {

/* Check which command they ran */
if (event.command.get_command_name() == "join") {
Expand Down Expand Up @@ -71,7 +71,7 @@ int main() {
}
});

bot.on_ready([&bot](const dpp::ready_t & event) {
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create a new command. */
bot.global_command_create(dpp::slashcommand("join", "Joins your voice channel.", bot.me.id));
Expand Down
2 changes: 1 addition & 1 deletion docpages/example_code/making_threads2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {
bot.on_log(dpp::utility::cout_logger());

/* The event is fired when the bot detects a message in any server and any channel it has access to. */
bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) {
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "message-thread") {
/* Get all active threads in a guild. */
Expand Down
6 changes: 3 additions & 3 deletions docpages/example_code/modal_dialog_interactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main() {

bot.on_log(dpp::utility::cout_logger());

bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
/* Check for our /dialog command */
if (event.command.get_command_name() == "dialog") {
/* Instantiate an interaction_modal_response object */
Expand Down Expand Up @@ -39,7 +39,7 @@ int main() {
});

/* This event handles form submission for the modal dialog we create above */
bot.on_form_submit([](const dpp::form_submit_t & event) {
bot.on_form_submit([](const dpp::form_submit_t& event) {
/* For this simple example, we know the elements value type is string.
* We also know the indices of each element.
* In the real world, it may not be safe to make such assumptions!
Expand All @@ -58,7 +58,7 @@ int main() {
event.reply(m);
});

bot.on_ready([&bot](const dpp::ready_t & event) {
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create a slash command and register it as a global command */
bot.global_command_create(dpp::slashcommand("dialog", "Make a modal dialog box", bot.me.id));
Expand Down
4 changes: 2 additions & 2 deletions docpages/example_code/mp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main() {
bot.on_log(dpp::utility::cout_logger());

/* The event is fired when someone issues your commands */
bot.on_slashcommand([&bot, &pcmdata](const dpp::slashcommand_t& event) {
bot.on_slashcommand([&pcmdata](const dpp::slashcommand_t& event) {
/* Check which command they ran */
if (event.command.get_command_name() == "join") {
/* Get the guild */
Expand Down Expand Up @@ -90,7 +90,7 @@ int main() {
}
});

bot.on_ready([&bot](const dpp::ready_t & event) {
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create a new command. */
dpp::slashcommand joincommand("join", "Joins your voice channel.", bot.me.id);
Expand Down
Loading
Loading