By default D++ does not cache messages. The example program below demonstrates how to instantiate a custom cache using dpp::cache which will allow you to cache messages and query the cache for messages by ID.
This can be adjusted to cache any type derived from dpp::managed including types you define yourself.
- Note
- This example will cache and hold onto messages forever! In a real world situation this would be bad. If you do use this, you should use the dpp::cache::remove() method periodically to remove stale items. This is left out of this example as a learning exercise to the reader. For further reading please see the documentation of dpp::cache
#include <dpp/dpp.h>
#include <sstream>
int main() {
*m = event.msg;
std::string cmd;
ss >> cmd;
if (cmd == "!get") {
ss >> msg_id;
if (find_msg != nullptr) {
} else {
}
}
});
return 0;
}
A cache object maintains a cache of dpp::managed objects.
Definition: cache.h:49
void store(T *object)
Store an object in the cache. Passing a nullptr will have no effect.
Definition: cache.h:100
T * find(snowflake id)
Find an object in the cache by id.
Definition: cache.h:153
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:491
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ i_message_content
Intent for receipt of message content.
Definition: intents.h:64
@ i_default_intents
Default D++ intents (all non-privileged intents)
Definition: intents.h:72
uint64_t snowflake
A 64 bit unsigned value representing many things on discord. Discord calls the value a 'snowflake' va...
Definition: snowflake.h:32
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:474
Create message.
Definition: dispatcher.h:1354
message msg
message that was created (sent).
Definition: dispatcher.h:1363
Represents messages sent and received on Discord.
Definition: message.h:1103
std::string content
Definition: message.h:1113
snowflake channel_id
Definition: message.h:1105