Debian Codegraph @

docpages/example_code/slashcommands4.cpp

raw symbols SCIP
1 #include <dpp/dpp.h>
2
3 int main() {
4 dpp::cluster bot("token");
5
6 bot.on_log(dpp::utility::cout_logger());
7
8 /* The event is fired when someone issues your commands */
9 bot.on_slashcommand([](const dpp::slashcommand_t& event) {
10 /* Check which command they ran */
11 if (event.command.get_command_name() == "ping") {
12 event.reply("Pong!");
13 } else if (event.command.get_command_name() == "pong") {
14 event.reply("Ping!");
15 } else if (event.command.get_command_name() == "ding") {
16 event.reply("Dong!");
17 } else if (event.command.get_command_name() == "dong") {
18 event.reply("Ding!");
19 }
20 });
21
22 bot.on_ready([&bot](const dpp::ready_t& event) {
23 if (dpp::run_once<struct register_bot_commands>()) {
24 /* Create some commands */
25 dpp::slashcommand pingcommand("ping", "Pong!", bot.me.id);
26 dpp::slashcommand pongcommand("pong", "Ping!", bot.me.id);
27 dpp::slashcommand dingcommand("ding", "Dong!", bot.me.id);
28 dpp::slashcommand dongcommand("dong", "Ding!", bot.me.id);
29
30 /* Register our commands in a list using bulk */
31 bot.guild_bulk_command_create({ pingcommand, pongcommand, dingcommand, dongcommand }, 857692897221033129);
32 }
33 });
34
35 bot.start(dpp::st_wait);
36
37 return 0;
38 }