Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: new cache example and file name fixes #862

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docpages/example_code/using_cache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#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;
}
3 changes: 2 additions & 1 deletion docpages/example_programs/the_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* \subpage editing-channels-and-messages
* \subpage using-cache
18 changes: 18 additions & 0 deletions docpages/example_programs/the_basics/using_cache.md
Original file line number Diff line number Diff line change
@@ -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.
braindigitalis marked this conversation as resolved.
Show resolved Hide resolved

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()`