| 1 | #include <dpp/dpp.h> |
| 2 | |
| 3 | int main() { |
| 4 | dpp::cluster bot("token"); |
| 5 | bot.on_log(dpp::utility::cout_logger()); |
| 6 | |
| 7 | bot.on_ready([&bot](const auto& event) { |
| 8 | if (dpp::run_once<struct boot_t>()) { |
| 9 | /** |
| 10 | * Create a slash command which has interaction context 'itc_private_channel'. |
| 11 | * This is a user-app command which can be executed anywhere and is added to the user's profile. |
| 12 | */ |
| 13 | bot.global_bulk_command_create({ |
| 14 | dpp::slashcommand("userapp", "Test user app command", bot.me.id) |
| 15 | .set_interaction_contexts({dpp::itc_guild, dpp::itc_bot_dm, dpp::itc_private_channel}) |
| 16 | }); |
| 17 | } |
| 18 | }); |
| 19 | |
| 20 | bot.register_command("userapp", [](const dpp::slashcommand_t& e) { |
| 21 | /** |
| 22 | * Simple test output that shows the context of the command |
| 23 | */ |
| 24 | e.reply("This is the `/userapp` command." + std::string( |
| 25 | e.command.is_user_app_interaction() ? |
| 26 | " Executing as a user interaction owned by user: <@" + e.command.get_authorizing_integration_owner(dpp::ait_user_install).str() + ">" : |
| 27 | " Executing as a guild interaction on guild id " + e.command.guild_id.str() |
| 28 | )); |
| 29 | }); |
| 30 | |
| 31 | bot.start(dpp::st_wait); |
| 32 | } |