Skip to content

Commit

Permalink
docs: new cache example and file name fixes (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
professor91 authored Sep 20, 2023
1 parent 785f283 commit 8ffbe74
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
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.

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

0 comments on commit 8ffbe74

Please sign in to comment.