D++ comes with many useful helper classes, but amongst these is something called dpp::collector. Collector is a template which can be specialised to automatically collect objects of a pre-determined type from events for a specific interval of time. Once this time period is up, or the class is otherwise signalled, a method is called with the complete set of collected objects.
In the example below we will use it to collect all reactions on a message.
#include <dpp/dpp.h>
public:
virtual void completed(
const std::vector<dpp::collected_reaction>& list)
override {
if (list.size()) {
owner->message_create(
dpp::message(list[0].react_channel->id,
"I collected " + std::to_string(list.size()) +
" reactions!"));
} else {
}
}
};
int main() {
react_collector* r = nullptr;
if (event.
msg.
content ==
"collect reactions!" && r ==
nullptr) {
r = new react_collector(&bot, event.msg.id);
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:82
Reaction collector. Collects message reactions during a set timeframe and returns them in a list via ...
Definition: collector.h:241
virtual void completed(const std::vector< dpp::collected_reaction > &list)=0
Return the completed collection.
A container for a 64 bit unsigned value representing many things on discord. This value is known in d...
Definition: snowflake.h:49
constexpr const char cl[]
Definition: unicode_emoji.h:5075
constexpr const char id[]
Definition: unicode_emoji.h:5047
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
The main namespace for D++ functions. classes and types.
Definition: appcommand.h:34
@ i_message_content
Intent for receipt of message content.
Definition: intents.h:65
@ i_default_intents
Default D++ intents (all non-privileged intents)
Definition: intents.h:73
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:65
Create message.
Definition: dispatcher.h:1483
message msg
message that was created (sent).
Definition: dispatcher.h:1490
Represents messages sent and received on Discord.
Definition: message.h:1212
std::string content
Definition: message.h:1222