Debian Codegraph @

docpages/example_code/detecting_messages.cpp

raw
1 #include <dpp/dpp.h>
2
3 int main() {
4 /* Create the bot, but with our intents so we can use messages. */
5 dpp::cluster bot("token", dpp::i_default_intents | dpp::i_message_content);
6
7 bot.on_log(dpp::utility::cout_logger());
8
9 /* The event is fired when the bot detects a message in any server and any channel it has access to. */
10 bot.on_message_create([](const dpp::message_create_t& event) {
11 /* See if the message contains the phrase we want to check for.
12 * If there's at least a single match, we reply and say it's not allowed.
13 */
14 if (event.msg.content.find("bad word") != std::string::npos) {
15 event.reply("That is not allowed here. Please, mind your language!", true);
16 }
17 });
18
19 bot.start(dpp::st_wait);
20
21 return 0;
22 }