D++ (DPP)  10.0.30
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.
Definition: user.h:180
dpp::i_default_intents
@ i_default_intents
Default D++ intents (all non-privileged intents).
Definition: intents.h:172
dpp::find_user
DPP_EXPORT class user * find_user(snowflake id)
Find an object in the cache by id.
Definition: cache.cpp:102
dpp.h
dpp::st_wait
@ st_wait
Wait forever on a condition variable.
Definition: cluster.h:101
dpp::user::format_username
std::string format_username() const
Format a username into user#discriminator.
Definition: user.cpp:151
main
int main()
Definition: soak.cpp:28
dpp::utility::cout_logger
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout.
Definition: dispatcher.h:228
dpp::i_guild_members
@ i_guild_members
Intent for receipt of guild members.
Definition: intents.h:82
dpp::message_reaction_remove_t::reacting_user_id
dpp::snowflake reacting_user_id
User who reacted.
Definition: dispatcher.h:1226
dpp::ll_info
@ ll_info
Information.
Definition: misc-enum.h:90
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