diff --git a/docpages/example_code/using_cache.cpp b/docpages/example_code/using_cache.cpp new file mode 100644 index 0000000000..8a93f2e881 --- /dev/null +++ b/docpages/example_code/using_cache.cpp @@ -0,0 +1,26 @@ +#include + +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; +} diff --git a/docpages/example_programs/the_basics/checking-member-permissions.md b/docpages/example_programs/misc/checking-member-permissions.md similarity index 100% rename from docpages/example_programs/the_basics/checking-member-permissions.md rename to docpages/example_programs/misc/checking-member-permissions.md diff --git a/docpages/example_programs/the_basics.md b/docpages/example_programs/the_basics.md index 74b462c035..0522b99d7e 100644 --- a/docpages/example_programs/the_basics.md +++ b/docpages/example_programs/the_basics.md @@ -7,4 +7,5 @@ These example programs are great to get started with simple things in the D++ li * \subpage attach-file "Attaching a file" * \subpage webhooks "Webhooks" * \subpage callback-functions "Using Callback Functions" -* \subpage editing-channels-and-messages \ No newline at end of file +* \subpage editing-channels-and-messages +* \subpage using-cache \ No newline at end of file diff --git a/docpages/example_programs/the_basics/using_cache.md b/docpages/example_programs/the_basics/using_cache.md new file mode 100644 index 0000000000..b1f2b2654f --- /dev/null +++ b/docpages/example_programs/the_basics/using_cache.md @@ -0,0 +1,18 @@ +\page using-cache 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{cpp} using_cache.cpp + +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()`