D++ (DPP)
C++ Discord API Bot Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Building a Discord Bot using CLion (Linux)
Warning
This tutorial assumes you are using Ubuntu. You might use other distros if you prefer, but keep in mind the setup process might be different! This tutorial also teaches you how to use DPP with CMake, using the JetBrains IDE CLion. If you have not installed CLion, You can download CLion here. If you do not have DPP installed, visit this page on how to setup the project using a precompiled version of DPP. If you want to use source and haven't set that up, look towards this page on how to do so. This tutorial will not teach you how to setup CMake and will assume you have already done so.

Add an example program

Open up CLion and open the folder for your bot. You may notice that CLion will start doing the whole CMake process and it will create a folder called cmake-build-debug, this is normal so don't be alarmed! It is just CLion registering all the CMake stuff so it can build and give you auto-suggestions.

Now, you can open your main.cpp file. If you have code there, then you're one step ahead! If not, copy and paste the following example program in the main.cpp and set your bot token (see Creating a Bot Token). Here's how your main.cpp file should look:

#include <dpp/dpp.h>
const std::string BOT_TOKEN = "add your token here";
int main() {
dpp::cluster bot(BOT_TOKEN);
bot.on_log(dpp::utility::cout_logger());
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
if (event.command.get_command_name() == "ping") {
event.reply("Pong!");
}
});
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(dpp::slashcommand("ping", "Ping pong!", bot.me.id));
}
});
bot.start(dpp::st_wait);
}

Now, you can go ahead and hit the green "Run" button in the top-right to run the bot.

Congratulations, you've successfully set up a bot!

If you're stuck, come find us on the official discord server! Ask away! We don't bite!

dpp::cluster::me
dpp::user me
The details of the bot user. This is assumed to be identical across all shards in the cluster....
Definition: cluster.h:274
dpp::managed::id
snowflake id
Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID,...
Definition: managed.h:79
dpp::slashcommand_t
User has issued a slash command.
Definition: dispatcher.h:779
dpp::st_wait
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:91
dpp::interaction_create_t::command
interaction command
command interaction
Definition: dispatcher.h:762
dpp::cluster::on_slashcommand
event_router_t< slashcommand_t > on_slashcommand
Called when a slash command is issued. Only dpp::ctxm_chat_input types of interaction are routed to t...
Definition: cluster.h:739
dpp::slashcommand
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:1416
dpp::utility::cout_logger
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
Definition: dispatcher.h:265
dpp::cluster::on_ready
event_router_t< ready_t > on_ready
Called when a shard is connected and ready. A set of cluster::on_guild_create events will follow this...
Definition: cluster.h:847
dpp::interaction::get_command_name
std::string get_command_name() const
Get the command name for a command interaction.
dpp::cluster::global_command_create
void global_command_create(const slashcommand &s, command_completion_event_t callback=utility::log_error())
Create a global slash command (a bot can have a maximum of 100 of these).
dpp::cluster::start
void start(start_type return_after=st_wait)
Start the cluster, connecting all its shards.
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:108
dpp::cluster::on_log
event_router_t< log_t > on_log
Called when a log message is to be written to the log. You can attach any logging system here you wis...
Definition: cluster.h:697
dpp::ready_t
Session ready.
Definition: dispatcher.h:1045
D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0