D++ (DPP)
C++ Discord API Bot Library
Using Cache

Sometimes you may need information that is not directly available in the event callback object.

To handle this DPP maintains a cache of commonly used data for you.

Note
As of August 30th, 2022, Discord made Guild Members a privileged intent. You must have GUILD_MEMBERS intent enabled for your app from discord developers portal to be able to look for members in cache.

Below is an example showing how to get a user from the cache

#include <dpp/dpp.h>
int main() {
/* Create bot */
/* This event is fired when someone removes their reaction from a message */
bot.on_message_reaction_remove([&bot](const dpp::message_reaction_remove_t& event) {
/* Find the user in the cache using his discord id */
dpp::user* reacting_user = dpp::find_user(event.reacting_user_id);
/* If user not found in cache, log and return */
if (!reacting_user) {
bot.log(dpp::ll_info, "User with the id " + std::to_string(event.reacting_user_id) + " was not found.");
return;
}
bot.log(dpp::ll_info, reacting_user->format_username() + " removed his reaction.");
});
bot.start(dpp::st_wait);
return 0;
}

DPP caches more than just users, which you can get using the below-mentioned functions:

dpp::user
Represents a user on discord. May or may not be a member of a dpp::guild.
Definition: user.h:182
dpp::i_default_intents
@ i_default_intents
Default D++ intents (all non-privileged intents).
Definition: intents.h:172
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:101
dpp::user::format_username
std::string format_username() const
Format a username into user#discriminator.
dpp::i_guild_members
@ i_guild_members
Intent for receipt of guild members.
Definition: intents.h:82
dpp::find_user
DPP_EXPORT class user * find_user(snowflake id)
dpp::message_reaction_remove_t::reacting_user_id
dpp::snowflake reacting_user_id
User who reacted.
Definition: dispatcher.h:1226
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:228
dpp::ll_info
@ ll_info
Information.
Definition: misc-enum.h:91
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:99
dpp::message_reaction_remove_t
Message reaction remove.
Definition: dispatcher.h:1214
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