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
- WebSocket: Beast
- Currently out of date
- WebSocket: Simple-WebSocket-Server
- WebSocket: Beast
- [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
callandsendfunctions to createstd::shared_ptrs 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 havegitstill track the remote repositiories- After adding the submodules you want, use
git submodule update --init --recursiveto 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
discordppand each module to yourINCLUDE_DIRECTORIEScommand.
INCLUDE_DIRECTORIES( ${discordpp_SOURCE_DIR} ${discordpp-rest-curlpp_SOURCE_DIR} ${discordpp-websocket-websocketpp_SOURCE_DIR})- In your code:
- Include
discordpp/bot.hhand 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
DppBotalias just after the#includestatements
using DppBot =
dpp::WebsocketBeast<
dpp::RestBeast<
dpp::Bot
>
>;- Add responses to events with
handlers.inserte.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). The token should be in the formBot <token>where you replace<token>with your token. - Run the bot:
bot->run();(This will also run the io_context)