### Install D++ using yay AUR helper Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-arch-aur.md An example of installing D++ using the `yay` AUR helper, which can often be done without root privileges. ```bash # example with `yay` (without root) yay -Sy dpp ``` -------------------------------- ### Install and Link libdpp with Homebrew Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-brew.md Installs the libdpp library and sets up necessary symbolic links for system-wide access. Run this first to get D++ installed. ```bash brew install libdpp brew link libdpp ``` -------------------------------- ### Basic Command Handler Setup Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/interactions_and_components/slashcommands/commandhandler.md This example demonstrates setting up a dpp::commandhandler to route both slash commands and prefixed message commands to a lambda function. It automatically hooks into the necessary cluster events. ```cpp #include #include int main() { dpp::cluster bot("YOUR_BOT_TOKEN", dpp::i_default_intents | dpp::i_message_content); // Instantiate the command handler dpp::commandhandler handler(bot); // Add a command that responds to both /ping and .ping handler.add_command("ping", { "Replies with pong!", // Description bot.me.get_guild_id() // Guild ID for testing }, // The command handler accepts a std::function, so you can use lambdas [](const std::string&, std::string args, void* userdata) -> std::string { return "pong!"; } ); // Automatically hook the events handler.enable_default_event_handlers(); bot.start(dpp::st_run); return 0; } ``` -------------------------------- ### Install to Default Location Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/linux.md After building, navigate to the build directory and use 'make install' to install the library to /usr/local/include and /usr/local/lib. ```bash cd build sudo make install ``` -------------------------------- ### Install Project Globally Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/freebsd.md After building, navigate to the build directory and run 'make install' to install the project globally on the system. ```bash cd build make install ``` -------------------------------- ### Install Project Globally Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/openbsd.md Navigates to the build directory and installs the project globally using make install. ```bash cd build; make install ``` -------------------------------- ### Install D++ using dpkg Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-linux-deb.md Installs D++ by first downloading the latest release using `wget` and then installing the `.deb` package with `dpkg`. Ensure you have `wget` installed or install it first. ```bash apt install wget wget -O dpp.deb https://dl.dpp.dev/ dpkg -i dpp.deb ``` -------------------------------- ### Manage Timers with Commands Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/misc/using_timers.md This example shows how to create and manage timers using Discord commands, storing them in a map to allow starting and stopping. It uses a map to associate timers with their owners. ```cpp #include #include #include // Structure to hold timer information struct timer_data { dpp::timer timer; dpp::snowflake owner_id; }; // Map to store active timers, keyed by a unique timer name std::map active_timers; // ... bot setup ... int main() { // ... bot setup ... // Command to start a timer bot.on_message_create([&](const dpp::message_create_t& event) { if (event.msg.content == "!start_timer") { std::string timer_name = "my_command_timer_"; timer_name += std::to_string(event.msg.author.id); if (active_timers.find(timer_name) == active_timers.end()) { timer_data td; td.owner_id = event.msg.author.id; td.timer.set_callback([&bot, timer_name](const dpp::timer& timer) { bot.execute_ சிகிச்ச("send_message", event.msg.channel_id, "Timer fired!"); // Remove the timer after it fires once active_timers.erase(timer_name); }); td.timer.start(bot, std::chrono::seconds(30)); // Timer runs for 30 seconds active_timers[timer_name] = td; bot.direct_message(event.msg.author.id, "Timer started!"); } else { bot.direct_message(event.msg.author.id, "You already have a timer running!"); } } // Command to stop a timer if (event.msg.content == "!stop_timer") { std::string timer_name = "my_command_timer_"; timer_name += std::to_string(event.msg.author.id); auto it = active_timers.find(timer_name); if (it != active_timers.end()) { it->second.timer.stop(); active_timers.erase(it); bot.direct_message(event.msg.author.id, "Timer stopped!"); } else { bot.direct_message(event.msg.author.id, "You don't have a timer running!"); } } }); // ... start the bot ... return 0; } ``` -------------------------------- ### Install dpp Library Source: https://github.com/brainboxdotcc/dpp/wiki/Building-on-Linux Installs the compiled library and headers to /usr/local/include and /usr/local/lib. ```bash sudo make install ``` -------------------------------- ### Install dpp Library to Custom Directory Source: https://github.com/brainboxdotcc/dpp/wiki/Building-on-Linux Installs the library to a specified custom directory. First, configure CMake with the desired installation prefix, then run make install. ```bash cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install make install ``` -------------------------------- ### Install D++ using RPM Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-linux-rpm.md Installs wget, downloads the latest D++ RPM package, and then installs the package locally. This process installs D++ to /usr. ```bash yum install wget wget -O dpp.rpm https://dl.dpp.dev/latest/linux-x64/rpm yum localinstall dpp.rpm ``` -------------------------------- ### Install to Custom Directory Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/linux.md Specify a custom installation prefix using CMAKE_INSTALL_PREFIX when configuring with CMake. Then, run 'make install' to deploy to the specified location. ```bash cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install ``` -------------------------------- ### CMakeLists.txt Configuration for D++ Examples Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_code/CMakeLists.txt This CMakeLists.txt file sets up the build environment for D++ example programs. It defines compiler flags, includes directories, and adds executables for each example source file, linking against required libraries. ```cmake cmake_minimum_required (VERSION 3.16) project(documentation_tests) include("${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/colour.cmake") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDPP_CORO -std=c++20 -pthread -O0 -fPIC -rdynamic -DFMT_HEADER_ONLY -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter -Wno-deprecated-declarations") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") file(GLOB example_list ./*.cpp) foreach (example ${example_list}) get_filename_component(examplename ${example} NAME) message(STATUS "Found example '${BoldBlue}${examplename}${ColourReset}'") add_executable(${examplename}_out ${example}) target_link_libraries(${examplename}_out dl dpp mpg123 oggz ogg opusfile opus) include_directories(/usr/include/opus) endforeach(example) ``` -------------------------------- ### Install D++ using VCPKG Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-vcpkg.md Use this command to install the D++ library and its dependencies for the x64 Windows target. ```cmd vcpkg install dpp:x64-windows ``` -------------------------------- ### Install Configuration and Version Files Source: https://github.com/brainboxdotcc/dpp/blob/master/library-vcpkg/CMakeLists.txt Installs the generated configuration and version files to the share/dpp directory. These files are used by CMake's find_package command. ```cmake install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_FILE_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/${VERSION_FILE_NAME}" DESTINATION "share/dpp" ) ``` -------------------------------- ### Install Apache and Modules Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/advanced_reference/shardless-webhook-events.md Installs Apache web server and necessary proxy modules on a Debian-based system. Restarts Apache to load the modules. ```sh sudo apt update sudo apt install apache2 -y sudo a2enmod proxy proxy_http ssl sudo systemctl restart apache2 ``` -------------------------------- ### Install Library Target Source: https://github.com/brainboxdotcc/dpp/blob/master/library-vcpkg/CMakeLists.txt Installs the library target, including runtime, archive, and export files. The installation path is conditional based on the build configuration (Debug/Release) and platform. ```cmake install( TARGETS "${LIB_NAME}" EXPORT "${EXPORTED_TARGETS_NAME}" RUNTIME DESTINATION "$<$>:$,${DEBUG_PREFIX}bin,bin>>" ARCHIVE DESTINATION "$,${DEBUG_PREFIX}lib,lib>" ) ``` -------------------------------- ### Install DPP Library and Headers (MinGW) Source: https://github.com/brainboxdotcc/dpp/blob/master/library/CMakeLists.txt Installs the DPP library and headers to specific locations within the installation prefix for MinGW builds. This handles the installation on Windows using the MinGW toolchain. ```cmake install(TARGETS dpp LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) install(DIRECTORY ../include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include) ``` -------------------------------- ### Join Voice Channel Example (C++) Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/music_and_audio/join_voice.md This C++ code snippet shows how to join the voice channel of the user issuing a command. It checks if the user is in a voice channel and handles cases where the bot is already connected. This example focuses on the connection logic and indicates where audio playback should be initiated. ```cpp #include #include /* * This example shows how to join the voice channel of the user issuing a command. * If you are already on the same voice channel, the bot should do nothing (but be ready to instantly play audio) and if the user is on a different voice channel, the bot should switch to it. If the user is on no voice channel at all, this should be considered an error. */ int main(int argc, char const *argv[]) { /* Bot token goes here */ std::string token = "YOUR_BOT_TOKEN"; /* The prefix for your bot commands */ std::string prefix = "!"; /* Create a new bot instance */ dpp::cluster bot(token, dpp::i_default_intents | dpp::i_guild_voice); /* Output simple log message to the console */ bot.on_log(dpp::utility::stream_logger()); /* Handle the slash command */ bot.on_message_create([&bot](const dpp::message_create_t &ev) { /* Check if the message starts with the prefix */ if (ev.msg.content.substr(0, prefix.length()) == prefix) { /* Get the command and arguments */ std::string command = ev.msg.content.substr(prefix.length()); std::string args; if (command.find(' ') != std::string::npos) { args = command.substr(command.find(' ') + 1); command = command.substr(0, command.find(' ')); } /* Join voice channel command */ if (command == "join") { /* Check if the user is in a voice channel */ dpp::guild_voice_state vstate = bot.get_guild_voice_state(ev.msg.guild_id, ev.msg.author.id); if (!vstate.channel_id.empty()) { /* Check if the bot is already in the same channel */ dpp::guild_voice_state bot_vstate = bot.get_guild_voice_state(ev.msg.guild_id, bot.me.id); if (bot_vstate.channel_id.empty()) { /* Bot is not in a voice channel, join the user's channel */ bot.socket->connect(vstate.channel_id, ev.msg.guild_id, false); bot.send_message(ev.msg.channel_id, "Joined voice channel."); } else if (bot_vstate.channel_id == vstate.channel_id) { /* Bot is already in the same channel */ bot.send_message(ev.msg.channel_id, "Already in your voice channel."); } else { /* Bot is in a different channel, switch to the user's channel */ bot.set_voice_state(ev.msg.guild_id, vstate.channel_id, false); bot.send_message(ev.msg.channel_id, "Switched to your voice channel."); } } else { /* User is not in a voice channel */ bot.send_message(ev.msg.channel_id, "You are not in a voice channel."); } } } }); /* Start the bot */ bot.start(dpp::st_wait); return 0; } ``` -------------------------------- ### Instantiate a Cluster Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/advanced_reference/clusters_shards_and_guilds.md This is how you instantiate a cluster when starting your bot. Replace 'Token goes here' with your actual bot token. ```cpp #include int main() { /* This is a cluster */ dpp::cluster bot("Token goes here"); } ``` -------------------------------- ### Install Dependencies and D++ Library Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/windows_wsl.md Install necessary dependencies like libopus0 and libopus-dev, then install the downloaded D++ .deb package. The rm command cleans up the downloaded file. ```bash sudo apt-get install libopus0 libopus-dev && sudo dpkg -i libdpp.deb && rm libdpp.deb ``` -------------------------------- ### Install Nginx Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/advanced_reference/shardless-webhook-events.md Installs Nginx on a Debian-based system. This is the first step in setting up Nginx as a reverse proxy. ```sh sudo apt update sudo apt install nginx -y ``` -------------------------------- ### Install External Dependencies Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/osx.md Installs OpenSSL and pkgconfig using Homebrew. Pkgconfig is usually not needed but can resolve OpenSSL errors. ```bash brew install openssl pkgconfig ``` -------------------------------- ### Install D++ Development Files Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-void-xbps.md Installs the D++ development files and related libraries from the XBPS source packages collection. This command should be run as root. ```bash xbps-install -Sy dpp-devel ``` -------------------------------- ### Basic Ping Pong Slash Command Example Source: https://github.com/brainboxdotcc/dpp/blob/master/README.md A simple example demonstrating how to create a Discord bot that responds to a "ping" slash command with "Pong!". Requires the BOT_TOKEN environment variable to be set. ```cpp #include #include int main() { dpp::cluster bot(std::getenv("BOT_TOKEN")); bot.on_slashcommand([](auto event) { if (event.command.get_command_name() == "ping") { event.reply("Pong!"); } }); bot.on_ready([&bot](auto event) { if (dpp::run_once()) { bot.global_command_create( dpp::slashcommand("ping", "Ping pong!", bot.me.id) ); } }); bot.start(dpp::st_wait); return 0; } ``` -------------------------------- ### Verify D++ Installation with VCPKG Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-vcpkg.md Check if the D++ package has been successfully installed by VCPKG. ```cmd c:\vcpkg>vcpkg list dpp dpp:x64-windows 10.0.29 D++ Extremely Lightweight C++ Discord Library. ``` -------------------------------- ### Example Discord Bot Program (C++) Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/clion.md This is a basic example program for a Discord bot. Replace 'YOUR_BOT_TOKEN' with your actual bot token. Ensure DPP is set up correctly. ```cpp #include int main() { dpp::cluster bot("YOUR_BOT_TOKEN"); bot.on_log(dpp::utility::spdlog_logger(std::to_string(bot.me.id))); bot.on_message_create([](const dpp::message_create_t& event) { if (event.msg.content == "!hello") { event.reply("Hello World!"); } }); bot.start(dpp::st_run_non_blocking); } ``` -------------------------------- ### Basic Discord Bot Main File Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/clion_windows.md This is an example `main.cpp` file for a basic Discord bot. Remember to replace the placeholder with your actual bot token. ```cpp #include #include int main() { /* Create a new bot instance with your token */ dpp::cluster bot("YOUR_BOT_TOKEN"); /* Output a message when the bot is connected to Discord */ bot.on_log(dpp::utility::cout_logger()); /* Handle the slash command */ bot.on_slashcommand("ping", [](const dpp::slashcommand_t& event) { event.reply("Pong!"); }); /* Start the bot */ bot.start(dpp::st_run) ;} ``` -------------------------------- ### Install CMake on FreeBSD Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/freebsd.md Use this command to install the CMake build system if it is not already present on your FreeBSD system. ```bash pkg install cmake ``` -------------------------------- ### CPack Setup for Packaging Source: https://github.com/brainboxdotcc/dpp/blob/master/library/CMakeLists.txt Includes the CPackSetup.cmake script to configure packaging and distribution options for the DPP library. This prepares the build for creating distributable packages. ```cmake include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/CPackSetup.cmake") # CPack initialization for distribution include(CPack) ``` -------------------------------- ### Simple Modal Dialog Example Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/interactions_and_components/modal_dialog_interactions.md This C++ example demonstrates how to create and display a simple modal dialog with a single text input field. It requires a slash command to trigger the dialog and handles the form submission event. ```cpp #include int main() { // Replace with your actual bot token dpp::cluster bot("YOUR_BOT_TOKEN"); // Event handler for when the bot is ready bot.on_ready([](const dpp::ready_t& event) { // Register the slash command dpp::slashcommand("dialog", "Show a modal dialog", bot.me.id) .set_application_id(bot.application_id) .register_globally(); }); // Event handler for slash command interactions bot.on_slashcommand([](const dpp::slashcommand_t& event) { // Check if the command is "dialog" if (event.command.get_command_name() == "dialog") { // Create a modal dialog dpp::modal modal("my_modal_id", "Enter your information"); // Add a text input field to the modal modal.add_input( dpp::component_modal_input(dpp::text_input_style::short, "name", "Your Name", true) ); // Show the modal to the user event.dialog(modal); } }); // Event handler for form submissions bot.on_form_submit([](const dpp::form_submit_t& event) { // Get the value from the text input field const std::string& name = event.get_value("name"); // Respond to the user with the submitted information event.reply("Hello, " + name + "!"); }); // Start the bot bot.start(dpp::st_wait); return 0; } ``` -------------------------------- ### Install Library Headers Source: https://github.com/brainboxdotcc/dpp/blob/master/library-vcpkg/CMakeLists.txt Installs the public header files of the library to the include directory. This makes the library's API accessible to users. ```cmake install( DIRECTORY "${DPP_ROOT_PATH}/include/" DESTINATION "include" ) ``` -------------------------------- ### Install Opus Audio Library on FreeBSD Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/freebsd.md If voice support is needed, navigate to the Opus port directory and build/install it using make. ```bash cd /usr/ports/audio/opus make && make install ``` -------------------------------- ### Install DPP Library and Headers (Non-Windows) Source: https://github.com/brainboxdotcc/dpp/blob/master/library/CMakeLists.txt Installs the DPP library, headers, and pkgconfig file to standard system locations for non-Windows platforms. It also runs a post-installation script for dynamic linker cache updates. ```cmake include(GNUInstallDirs) install(TARGETS dpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) message("Library install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") install(DIRECTORY ../include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) message("Include files install directory at ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -DRUN_LDCONFIG=${RUN_LDCONFIG} -DLDCONFIG_EXECUTABLE=${LDCONFIG_EXECUTABLE} -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/PostInstall.cmake)") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../dpp.pc.in" "${CMAKE_BINARY_DIR}/dpp.pc" @ONLY) install(FILES "${CMAKE_BINARY_DIR}/dpp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ``` -------------------------------- ### Conan Install and CMake Build Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-conan.md Install Conan dependencies, configure CMake with the Conan toolchain, and build your project. Ensure the build_type matches your CMake settings. ```bash mkdir build conan install . --output-folder=build --build=missing -s build_type=Release cd build cmake .. -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" cmake --build build --config Release ``` -------------------------------- ### Check Meson Version Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/meson.md Verify that Meson is installed on your system by checking its version. ```bash meson --version 0.63.2 ``` -------------------------------- ### Initialize Meson Project Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/meson.md Create a new, empty directory and initialize a C++ Meson project within it. ```bash meson init -l cpp ``` -------------------------------- ### Start the Bot and Set Logging Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/the_basics/firstbot.md Initiate the bot's connection and operation using dpp::cluster::start. Configure logging to output information to the console using dpp::utility::cout_logger. ```cpp bot.on_log(dpp::utility::cout_logger()); // Start the bot. bot.start(dpp::st_wait); ``` -------------------------------- ### Build Meson Project Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/meson.md Set up the build directory and compile the Meson project. This command prepares the project for building and then compiles the code. ```bash meson setup builddir meson compile -C builddir ``` -------------------------------- ### Create Bot Directory and File Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/windows_wsl.md Create a new directory for your bot project and navigate into it. Then, create a new C++ source file for your bot's code. ```bash mkdir MyBot cd MyBot touch mybot.cxx ``` -------------------------------- ### Create a User Application Command Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/interactions_and_components/user_apps.md This C++ example demonstrates how to create a slash command for a user application. It highlights setting interaction contexts to make the command visible in user applications and how to handle responses when guild-specific information is unavailable. ```cpp #include int main() { // Create a bot client dpp::cluster bot("YOUR_BOT_TOKEN", dpp::i_default_intents | dpp::i_message_content); // Event handler for when the bot is ready bot.on_ready([&bot](const dpp::ready_t& event) { std::cout << "Logged in as " << bot.me.username << "\n"; // Define the user application command dpp::slashcommand user_app_command("userapp", "A command for user apps!", bot.me.get_guild_id()); // Set the interaction contexts for the command // dpp::itc_guild: Standard guild command // dpp::itc_bot_dm: Command accessible in DMs with the bot // dpp::itc_private_channel: User application command, visible anywhere to the user user_app_command.set_interaction_contexts({ dpp::itc_private_channel }); // Register the command globally bot.global_commands.emplace_back(user_app_command); bot.submit_globally_commands(); }); // Event handler for slash command interactions bot.on_interaction([&bot](const dpp::interaction_create_t& event) { if (event.get_command().get_command_name() == "userapp") { // Check if the interaction is from a user app if (event.get_interaction().is_user_app_interaction()) { // Get the user ID who authorized the integration dpp::snowflake user_id = event.get_interaction().get_authorizing_integration_owner(dpp::ait_user_install); std::string response_text = "Hello, " + event.get_command().usr.username + "! This is a user app command."; // Respond to the interaction bot.direct_message_create(user_id, "You used the user app command!"); event.reply("User app command executed successfully!"); } else { event.reply("This command is intended for user apps only."); } } }); // Start the bot bot.start(dpp::st_wait); return 0; } ``` -------------------------------- ### Discord.js Bot Example Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/the_basics/firstbot.md This is a JavaScript example of a Discord bot that responds to a '/ping' command. ```javascript let Discord = require('discord.js'); let BOT_TOKEN = 'add your token here'; let bot = new Discord.Client({ intents: [] }); bot.on('interactionCreate', (interaction) => { if (interaction.isCommand() && interaction.commandName === 'ping') { interaction.reply({content: 'Pong!'}); } }); bot.once('ready', async () => { await client.commands.create({ name: 'ping', description: "Ping pong!" }); }); bot.login(BOT_TOKEN);‍ ``` -------------------------------- ### Install CMake on OpenBSD Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/openbsd.md Installs the CMake build system using the OpenBSD package manager. ```bash pkg_add cmake ``` -------------------------------- ### Create and Handle Generic Select Menu Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/interactions_and_components/components/components3.md This snippet demonstrates creating a basic select menu with text options and handling user selections. Ensure you have the necessary Discord API client setup. ```cpp #include int main() { // Replace with your actual bot token dpp::cluster bot("YOUR_BOT_TOKEN"); // Event handler for when the bot is ready bot.on_ready([&bot](const dpp::ready_t& event) { // Define the select menu options dpp::select_option::option_list options; options.push_back(dpp::select_option("Option 1", "option1", "This is the first option.")); options.push_back(dpp::select_option("Option 2", "option2", "This is the second option.")); options.push_back(dpp::select_option("Option 3", "option3", "This is the third option.")); // Create the select menu component dpp::component select_menu(dpp::component_type::cot_selectmenu, dpp::selectmenu_type::smt_text); select_menu.set_placeholder("Choose an option...").add_options(options); // Create a message with the select menu dpp::message msg; msg.set_content("Please select an option:").add_component(dpp::component().add_component(select_menu)); // Send the message to a specific channel (replace with your channel ID) bot.message_create(msg.set_channel_id(YOUR_CHANNEL_ID)); }); // Event handler for select menu interactions bot.on_form_submit([&bot](const dpp::form_submit_t& event) { // Get the selected value from the first select menu component std::string selected_value = event.components[0].get_value(0); // Respond to the interaction with the selected value event.reply("You selected: " + selected_value); }); // Start the bot bot.start(dpp::st_wait); return 0; } ``` -------------------------------- ### Install Opus for Voice Support Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/osx.md Installs the Opus audio codec library, which is an additional dependency for voice support. ```bash brew install opus ``` -------------------------------- ### Install Export Set Source: https://github.com/brainboxdotcc/dpp/blob/master/library-vcpkg/CMakeLists.txt Installs the export set for the library, which allows other CMake projects to find and link against this library using `find_package`. ```cmake install( EXPORT "${EXPORTED_TARGETS_NAME}" FILE "${EXPORTED_TARGETS_FILE_NAME}" NAMESPACE "${PROJECT_NAME}::" DESTINATION "share/dpp" ) ``` -------------------------------- ### Create and Handle User Context Menu Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/interactions_and_components/context_menus.md This example demonstrates how to register a guild command that appears when right-clicking a user. To make it appear on a message, change the type to dpp::ctxm_message and listen for the on_message_context_menu event. ```cpp #include int main() { dpp::cluster bot("YOUR_TOKEN", dpp::i_default_intents | dpp::i_message_content); bot.on_log(dpp::utility::logger()); // Create a context menu command dpp::slashcommand context_menu("userinfo", dpp::ctxm_user, "Get user info"); context_menu.set_default_permissions(dpp::permissions::p_read_message_history); bot.on_message_context_menu([&bot](const dpp::message_context_menu_t& event) { // This event is for message context menus, but we are handling user context menus here. // The actual user context menu handling is done in on_user_context_menu. // This is a placeholder to avoid compilation errors if you were to switch to message context menus. }); bot.on_user_context_menu([&bot](const dpp::user_context_menu_t& event) { // This is where the user context menu is handled dpp::user u = event.get_user(); dpp::embed embed; embed.set_title("User Info") .set_thumbnail(u.get_avatar_url()) .add_field("Username", u.format_username()) .add_field("ID", std::to_string(u.id)); event.reply(dpp::message(event.channel_id, embed)); }); bot.on_ready([&](const dpp::ready_t& event) { // Register the command globally if (dpp::run_once()) { bot.global_commands.push_back(context_menu); bot.submit_globally_commands(); } }); bot.start(dpp::st_wait); return 0; } ``` -------------------------------- ### Install PDB Files on Windows Source: https://github.com/brainboxdotcc/dpp/blob/master/library-vcpkg/CMakeLists.txt Conditionally installs the Program Database (PDB) files for the library on Windows systems. PDB files are used for debugging. ```cmake if (WIN32) install( FILES "$<$ DESTINATION "$,${DEBUG_PREFIX}bin,bin>" OPTIONAL ) endif() ``` -------------------------------- ### Install Opus Voice Dependency on OpenBSD Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/building/openbsd.md Installs the Opus audio codec library, required for voice support, using the OpenBSD package manager. ```bash pkg_add opus ``` -------------------------------- ### Install D++ from AUR using makepkg Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/install/install-arch-aur.md Clone the AUR repository, navigate into the directory, and build/install the package using makepkg. This process requires root privileges. ```bash git clone https://aur.archlinux.org/dpp.git cd dpp makepkg -si ``` -------------------------------- ### Create a Thread Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/misc/making_threads.md Demonstrates how to create a new thread within a channel. Ensure you have the necessary permissions. ```cpp #include void thread_creation(dpp::cluster& cluster) { cluster.on_message_create([&](const dpp::message_create_t& event) { if (event.msg.content == "!createthread") { dpp::channel thread_channel; thread_channel.name = "my-new-thread"; thread_channel.type = dpp::channel_type::CHANNEL_PUBLIC_THREAD; thread_channel.message_id = event.msg.id; cluster.channel_create(thread_channel, [&](const dpp::confirmation_callback_t& callback) { if (callback.is_error()) { cluster.log(dpp::loglevel::error, "Error creating thread: " + callback.get_error_msg()); } }); } }); } ``` -------------------------------- ### C++ Slash Command Autocompletion Example Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/interactions_and_components/slashcommands/autocomplete.md Implement autocompletion for slash commands using this C++ example. Ensure you have the necessary Discord API libraries integrated. ```cpp #include // ... other code ... // This is a basic example of how to implement autocompletion for a slash command. // The command will be named "autocomplete" and will have one option, "choice". dpp::slashcommand autocomplete_command("autocomplete", "A command with autocomplete", BOT_TOKEN, "/autocomplete"); autocomplete_command.add_option( dpp::command_option(dpp::co_string, "choice", "Pick a choice!") .set_auto_increment(true) // This enables autocompletion ); // When the command is run, we want to respond with the choice the user made. bot.on_slashcommand([&](const dpp::slashcommand_t& event) { if (event.command.get_command_name() == "autocomplete") { // Get the choice the user made. std::string choice = std::get(event.input_values[0]); // Respond to the user. event.reply("You chose: " + choice); } }); // This is the function that will be called when the user types in the command. // It will be called with the current input of the user, and the command object. // We will return a list of choices that the user can pick from. bot.on_autocomplete( "autocomplete", // The name of the command to autocomplete [&](const dpp::autocomplete_t& event) { // Get the current input of the user. std::string input = std::get(event.options[0].value); // Create a list of choices. dpp::autocomplete_choices choices; choices.add("Choice 1", "choice1"); choices.add("Choice 2", "choice2"); choices.add("Choice 3", "choice3"); // Filter the choices based on the user's input. event.reply(choices.contrain(input)); } ); // ... other code ... ``` -------------------------------- ### Download and Extract libdpp Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/replit.md Use wget to download the precompiled x64 libdpp release and dpkg to extract it into the current directory. This prepares the library for use in your Replit environment. ```bash wget -O libdpp.deb https://dl.dpp.dev/latest ``` ```bash dpkg -x libdpp.deb . ``` -------------------------------- ### Run Bot with LD_PRELOAD Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/replit.md Execute your compiled bot, setting the LD_PRELOAD environment variable to point to the libdpp.so located in your home directory. This is necessary because the library is not installed in the system's default library path. ```bash LD_PRELOAD=./usr/lib/libdpp.so ./bot ``` -------------------------------- ### Coroutine Example with dpp::task Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/example_programs/using_coroutines/coro_introduction.md This example demonstrates how to create a coroutine using `dpp::task`. Coroutines can be used for event handlers and attached to event routers. Ensure to use `co_await` for awaitable types and `co_return` to signal completion. ```cpp #include dpp::task message_create_coro(const dpp::message_create_t& event) { // Example of using co_await with a dpp::async call // The coroutine will pause here until the message is created dpp::message msg = co_await dpp::cluster::co_message_create( dpp::message("Hello from coroutine!").set_channel_id(event.channel_id) ); // The coroutine resumes here after the message is created // You can perform further actions with the created message or other data // For example, logging or sending another message co_return; } ``` -------------------------------- ### Create config.json Source: https://github.com/brainboxdotcc/dpp/wiki/Building-on-Windows Create a config.json file with bot token and shard count for the test bot. ```json { "token": "YOUR_BOT_TOKEN", "shard_count": 1 } ``` -------------------------------- ### Check CMake Version Source: https://github.com/brainboxdotcc/dpp/blob/master/docpages/make_a_bot/cmake.md Verifies if CMake is installed on the system. Any version is acceptable. ```bash $ cmake --version cmake version 3.22.1 ```