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;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:80
Represents a user on discord. May or may not be a member of a dpp::guild.
Definition: user.h:163
std::string format_username() const
Format a username into user#discriminator.
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ i_guild_members
Intent for receipt of guild members.
Definition: intents.h:42
@ i_default_intents
Default D++ intents (all non-privileged intents).
Definition: intents.h:132
@ ll_info
Information.
Definition: misc-enum.h:71
DPP_EXPORT class user * find_user(snowflake id)
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:63
Message reaction remove.
Definition: dispatcher.h:1194
dpp::snowflake reacting_user_id
User who reacted.
Definition: dispatcher.h:1206

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

D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ 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