A Modularized C++ Library for the Discord API
This library is not a hacked Discord mobile app that will give you free Nitro. Free Nitro does not exist, and any YouTube video saying otherwise is attempting either to get you to install malware or to collect ad revenue off of you.
- Boost
- A Discord++ REST module
- REST: Beast
- Requires OpenSSL
- REST: Beast
- A Discord++ WebSocket module
- [Incomplete] Plugin: RateLimit handes rate limiting
- Without this plugin, Discord++ exits when encountering a rate limit for your safety
- Plugin: Overload provides overloads for the websocket and REST
call
andsend
functions to createstd::shared_ptr
s for you and provides some sane defaults when you don't need all their arguments. - Plugin: Responder provides a simple interface for detecting commands in the form of a character and a string, e.g.
!help
- You can find more plugins on the #discordpp-plugin tag
- Echo Bot
- Contains detailed setup instructions
- Branches often track development of new features
- Feel free to submit your own templates as a PR
- Download:
- Download Discord++, a Discord++ REST module, a Discord++ Websocket module, and any plugins you want.
git submodule add <repository> [<path>]
is a nice way to havegit
still track the remote repositiories- After adding the submodules you want, use
git submodule update --init --recursive
to initialize them.
- After adding the submodules you want, use
- Place them all in a subdirectory of your project. (I use
lib/
)
- In CMake:
- Add
ADD_SUBDIRECTORY(<relative path>)
for Discord++ and each module. e.g.
add_subdirectory(lib/discordpp)
add_subdirectory(lib/rest-curlpp)
add_subdirectory(lib/websocket-websocketpp)
- Add
discordpp
and each module to yourINCLUDE_DIRECTORIES
command.
INCLUDE_DIRECTORIES( ${discordpp_SOURCE_DIR} ${discordpp-rest-curlpp_SOURCE_DIR} ${discordpp-websocket-websocketpp_SOURCE_DIR})
- In your code:
- Include
discordpp/bot.hh
and the header file from each submodule. e.g.
#include <discordpp/bot.hh>
#include <discordpp/rest-curlpp.hh>
#include <discordpp/websocket-websocketpp.hh>
- Create a Bot object. e.g.
auto bot = std::make_shared<DppBot>();
- For this example, I declared a
DppBot
alias just after the#include
statements
using DppBot =
dpp::WebsocketBeast<
dpp::RestBeast<
dpp::Bot
>
>;
- Add responses to events with
handlers.insert
e.g.
bot->handlers.insert(
{
"MESSAGE_CREATE",
[&bot](json msg){
//Do Stuff
}
}
);
- Create a
std::shared_ptr<boost::asio::io_context>
- e.g.
auto aioc = std::make_shared<asio::io_context>();
- e.g.
- Initialize the bot object and any plugins that require it e.g.
bot->initBot(6, token, aioc)
. - Run the bot:
bot->run();
(This will also run the io_context)