/discordpp

A Modularized C++ Library for the Discord API

Primary LanguageC++

Discord++ (it's cool)

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.

GitHub starsDiscord

Links

Dependencies

Required

Included (Git submodules)

Recommended Plugins

  • [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 and send functions to create std::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

Usage

Templates This is way easier

  • Echo Bot
    • Contains detailed setup instructions
    • Branches often track development of new features
  • Feel free to submit your own templates as a PR

Manual

  • Download:
  1. 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 have git still track the remote repositiories
      • After adding the submodules you want, use git submodule update --init --recursive to initialize them.
  2. Place them all in a subdirectory of your project. (I use lib/)
  • In CMake:
  1. 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)
  1. Add discordpp and each module to your INCLUDE_DIRECTORIES command.
INCLUDE_DIRECTORIES( ${discordpp_SOURCE_DIR} ${discordpp-rest-curlpp_SOURCE_DIR} ${discordpp-websocket-websocketpp_SOURCE_DIR})
  • In your code:
  1. 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>
  1. 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
		>
>;
  1. Add responses to events with handlers.insert e.g.
bot->handlers.insert(
	{
		"MESSAGE_CREATE",
		[&bot](json msg){
			//Do Stuff
		}
	}
);
  1. Create a std::shared_ptr<boost::asio::io_context>
    • e.g. auto aioc = std::make_shared<asio::io_context>();
  2. Initialize the bot object and any plugins that require it e.g. bot->initBot(6, token, aioc).
  3. Run the bot: bot->run(); (This will also run the io_context)