| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
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 */
dpp::cluster bot("token", dpp::i_default_intents | dpp::i_guild_members);
bot.on_log(dpp::utility::cout_logger());
/* 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::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition cluster.h:89
dpp::user
Represents a user on discord. May or may not be a member of a dpp::guild.
Definition user.h:163
dpp::user::format_username
std::string format_username() const
Format a username into user#discriminator.
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.
dpp::i_guild_members
@ i_guild_members
Intent for receipt of guild members.
Definition intents.h:42
dpp::i_default_intents
@ i_default_intents
Default D++ intents (all non-privileged intents).
Definition intents.h:142
dpp::ll_info
@ ll_info
Information.
Definition misc-enum.h:71
dpp::find_user
DPP_EXPORT class user * find_user(snowflake id)
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:72
dpp::message_reaction_remove_t
Message reaction remove.
Definition dispatcher.h:1305
dpp::message_reaction_remove_t::reacting_user_id
dpp::snowflake reacting_user_id
User who reacted.
Definition dispatcher.h:1317

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

- dpp::find_role()
- dpp::find_channel()
- dpp::find_emoji()
- dpp::find_guild()
- dpp::find_guild_member()

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0