-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: new cache example and file name fixes (#862)
- Loading branch information
1 parent
785f283
commit 8ffbe74
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()` |