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() {
});
if (!find_msg) {
event.reply("There is no message cached with this ID");
return;
}
event.reply(
"This message had the following content: " + find_msg->
content);
}
});
if (dpp::run_once<struct register_bot_commands>()) {
dpp::slashcommand newcommand(
"get",
"Get the contents of a message that was cached via an id", bot.me.id);
bot.global_command_create(newcommand);
}
});
return 0;
}