| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
Listening to messages

Sometimes, you may want to listen out for a message, rather than a command. This could be used for many cases like a spam filter, a bot that would respond to movie quotes with gifs, or a chat bot! However, in this page, we'll be using this to create a moderation filter (detect bad words).

Warning
  As of August 30th, 2022, Discord made Message Content a privileged intent. Whilst this means you can still use prefixed messages as commands, Discord does not encourage this and heavily suggests you use slash commands. If you wish to create commands, use slash commands, not messages.

#include <dpp/dpp.h>
int main() {
/* Create the bot, but with our intents so we can use messages. */
dpp::cluster bot("token", dpp::i_default_intents | dpp::i_message_content);
bot.on_log(dpp::utility::cout_logger());
/* The event is fired when the bot detects a message in any server and any channel it has access to. */
bot.on_message_create([](const dpp::message_create_t& event) {
/* See if the message contains the phrase we want to check for.
* If there's at least a single match, we reply and say it's not allowed.
*/
if (event.msg.content.find("bad word") != std::string::npos) {
event.reply("That is not allowed here. Please, mind your language!", true);
}
});
bot.start(dpp::st_wait);
return 0;
}
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition cluster.h:89
dpp::utility::cout_logger
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
dpp::i_message_content
@ i_message_content
Intent for receipt of message content.
Definition intents.h:112
dpp::i_default_intents
@ i_default_intents
Default D++ intents (all non-privileged intents).
Definition intents.h:142
dpp::st_wait
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition cluster.h:72
dpp::message_create_t
Create message.
Definition dispatcher.h:1746
dpp::message_create_t::msg
message msg
message that was created (sent).
Definition dispatcher.h:1753
dpp::message::content
std::string content
Contents of the message.
Definition message.h:2408

If all went well, you should have something like this!

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0