D++ (DPP)
10.0.30
C++ Discord API Bot Library
|
|
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 <sstream>
});
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;
}
@ i_default_intents
Default D++ intents (all non-privileged intents).
Definition: intents.h:172
User has issued a slash command.
Definition: dispatcher.h:715
A cache object maintains a cache of dpp::managed objects.
Definition: cache.h:70
std::string content
Contents of the message.
Definition: message.h:2052
@ st_wait
Wait forever on a condition variable.
Definition: cluster.h:101
void store(T *object)
Store an object in the cache.
Definition: cache.h:121
virtual command_value get_parameter(const std::string &name) const
Get a slashcommand parameter.
Definition: dispatcher.cpp:261
int main()
Definition: soak.cpp:28
Create message.
Definition: dispatcher.h:1655
Represents messages sent and received on Discord.
Definition: message.h:2007
interaction command
command interaction
Definition: dispatcher.h:698
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout.
Definition: dispatcher.h:228
@ i_message_content
Intent for receipt of message content.
Definition: intents.h:152
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:1358
@ co_string
A string value.
Definition: appcommand.h:83
std::string get_command_name() const
Get the command name for a command interaction.
Definition: slashcommand.cpp:487
T * find(snowflake id)
Find an object in the cache by id.
Definition: cache.h:174
Each command option is a command line parameter.
Definition: appcommand.h:222
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:99
constexpr const char m[]
Definition: unicode_emoji.h:5304
Session ready.
Definition: dispatcher.h:981