C++ Discord API Bot Library
This library powers the bot TriviaBot which has over 111,000 servers, and Sporks which has over 2,800 severs. The library's use in these bots shows that the library is production ready for bots of all sizes.
In production on TriviaBot, the bot takes approximately 2gb of ram to run 18 separate processes (this is approximately 140mb per process) on a production bot with 11 million users and 111,000 guilds. Each process takes under 1% CPU. This is less than a quarter of the memory of a similar C++ Discord library, Aegis.cpp (version 2).
For a very small bot, you can get the memory usage as low as 6 megabytes on a Raspberry Pi.
The easiest way is to download the precompiled latest release from our GitHub releases, and take the dlls, .lib file, and header files (
include directories), placing them in a easily accessible place on your computer. Go into Visual Studio project settings in a new project, and point the project directories (notably the library directories and and include directories) at the correct locations. Add the
include folder you extracted to your include directories, and add
dpp.lib to your library directories. Ensure the project is set to C++17 standard in the settings. You should then be able to compile example programs within that project. When you run the program you have compiled you must ensure that all the dll files from the
bin directory exist in the same directory as your executable.
Yes! The master branch comes with pre-built binaries for Visual Studio 2022 and our windows bot template has a vs2022 branch which you can clone to get Visual Studio 2022 specific code. For the time being we support both Visual Studio 2019 and 2022. At some point in the future only 2022 may be supported as 2019 becomes outdated.
All REST calls (outbound commands) are completed including all currently available interactions, and all Discord events are available. The library also has voice support.
The best place to do this is on the Discord server. You most likely won't get an answer immediately (we have lives, and need to sleep sometimes), but we will be willing to help!
Just star and fork a copy of the repository, and submit a Pull Request! We won't bite! Authors of accepted pull requests get a special role on our Discord server.
A simple search can find some learning tools, however not all are good. Here is a list of some (good) learning resources:
If you don't understand something then feel free to ask in the Discord server ...*we don't bite!*
NO! Definitely not! We have tried to keep things as simple as possible. We only use language features where they make sense, not just because they exist. Take a look at the example program (
test.cpp and you'll see just how simple it is to get up and running quickly). We use a small subset of C++17 and C++14 features.
DPP is short for D Plus Plus (D++), a play on the Discord and C++ names. You'll see the library referred to as
dpp within source code as
d++ is not a valid symbol so we couldn't exactly use that as our namespace name.
No, D++ is a classically designed library which installs itself to your library directory/system directory as a shared object or dll. You must link to its .lib file and include its header files to make use of it. We have no plans for a single-header build.
Yes! This library supports slash commands and interactions. For more information please see Using Slash Commands and Interactions.
Yes! This library supports button message components, e.g. interactive buttons on the bottom of messages. For more information please see our Using component interactions and Using component interactions (advanced) examples.
All functions within D++ are multi-threaded. You should still avoid doing long operations within event handlers or within callbacks, to prevent starvation of the threads managing each shard. Various blocking operations such as running files and making HTTP requests are offered as library functions (for example dpp::utility::exec)
Yes! This library supports voice and will automatically enable voice if your system has the libopus and libsodium libraries. When running
cmake the script will identify if these libraries are found. See the example programs for information on how to send audio.
Yes! D++ supports sharding and also clustering (grouping of shards into one process) to ensure it is scalable for small and large bots alike.
The documentation and website are built using Doxygen. To contribute to site pages, submit a Pull Request to the main repository. The site pages can be found within the
docpages directory. Details of classes, variables, namespaces etc are auto generated from Doxygen comments within the library source code in the
D++ only supports Discord API v9, the latest version.
Yes! D++ supports Discord threads. You can create, edit and delete threads and also attach events watching for messages within threads.
No, at the current time we do not use any C++20 features. Some C++17 features are used, which are available in all recent compilers.
To fix this issue, run
sudo ldconfig as root. Log out if your SSH session and log back in, and the bot should be able to find the library.
The libsodium package requires pkg-config, but does not check for it when installed. Install it as root, e.g.
sudo apt install pkg-config. Rerun cmake, and rebuild the library.
If this happens, ensure you are using the correct precompiled build of the library. Our precompiled binaries are built in two forms, release mode and debug mode for Visual Studio 2019. If you require a build for a newer Visual Studio version, you will have to compile it yourself from the GitHub sources. Please see the section about Building on Windows for more information on how to do this.
Yes! This project will build and run on Raspberry Pi and is very much suited to this kind of system. It may take some time (read: hours) to compile the project on your Raspberry Pi unless you build it using a cross compiler. We offer pre-built
.deb files for arm6, arm7 and arm64, you should use these where possible to avoid having to compile it by hand, or you can use a cross-compiler to build it on your PC then transfer the compiled binaries across.
Depending on which Raspberry Pi version you have, you will need to download a different release binary:
|Raspberry Pi Model||Deb file to install||Arch|
|Raspberry Pi Zero/Zero W||ARMv6|
|Raspberry Pi 3||ARMv7HF|
|Raspberry Pi 4||ARMv7HF|
|Raspberry Pi 4 with 64 Bit Linux||ARM64|
Yes! We have confirmed that the D++ deb file will successfully install and operate on various forms of cellphone or non-pi ARM devices. If you get it working on any other devices please let us know and we can build a compatibility chart.
All the functions that obtain data directly from Discord (as opposed to the cache) perform HTTPS requests and may have to wait, either for the request itself or for their turn in a queue to respect rate limits. As such, it does not make sense that they should return a value, as this would mean they block execution of your event. Instead, each has a lambda, a function handler which receives the result of the request, which you can then read from within that function to get the data you are interested in. Note that this result will arrive on a different thread to the one which made the request.