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:
react_collector(
dpp::cluster* cl, snowflake
id) :
dpp::message_collector(cl, 20, id) { }
virtual void completed(
const std::vector<dpp::collected_reaction>& list) {
if (list.size()) {
owner->message_create(
dpp::message(list[0].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);
}
});
bot.start(false);
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:384
Reaction collector. Collects message reactions during a set timeframe and returns them in a list via ...
Definition: dpp.h:130
virtual void completed(const std::vector< dpp::collected_reaction > &list)=0
Return the completed collection.
The main namespace for D++ functions. classes and types.
Definition: application.h:27
Create message.
Definition: dispatcher.h:1156
message msg
message that was created (sent).
Definition: dispatcher.h:1165
Represents messages sent and received on Discord.
Definition: message.h:1010
std::string content
Definition: message.h:1020