Skip to content

Commit fd170de

Browse files
docs: add documentation page for creating user app commands! (#1305)
1 parent 37e50a0 commit fd170de

File tree

7 files changed

+101
-0
lines changed

7 files changed

+101
-0
lines changed

docpages/example_code/user_apps.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

docpages/example_programs/interactions_and_components.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Interactions are a unified way provided by Discord to handle \ref slashcommands
44

55
* \subpage slashcommands-menu
66
* \subpage user-only-messages
7+
* \subpage user-applications
78
* \subpage resolved-objects
89
* \subpage components-menu
910
* \subpage modal-dialog-interactions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
\page user-applications Creating User Apps
2+
3+
# What are User Apps?
4+
5+
A user app is a bot (application) which can be attached to a user's profile via oauth, rather than being invited to a guild via oauth. This is a relatively new feature
6+
on Discord, and will allow you to have your bot to act like a utility for the user, so regardless of what guild they are in, or if they are in a DM with someone else,
7+
they have access to your bot's commands and can issue them, potentially letting all users in that guild, or all users in the DM, see the replies from your slash commands.
8+
9+
\warning Do not confuse User Apps with **User Bots**. User Apps are a new and very well supported feature, whereas **User Bots** means connecting a user's token as a bot,
10+
and is prohibited by the Discord TOS!
11+
12+
# Building the invite
13+
14+
To get started, you will need to configure your bot so that it will accept a user app invite. This is done via the [discord developer portal](https://discord.com/developers).
15+
16+
Click on your bot in the list of bots, and then choose **Installation** from the left hand menu. You must enable **User Install** if it is not already enabled.
17+
18+
Drop down the choices for **Install link** and change this to **Discord Provided Link**. The second box should auto-fill with an invite link. Note that this invite link
19+
will likely only show the **client_id** value. For default install settings for **User Install**, choose the only possible option, **applications.commands** and for the
20+
**Guild Install** section, choose the scopes **applications.commands** and **bot** as at least the bare minimum. You should also set the permissions your bot will use if it
21+
is invited to a guild.
22+
23+
\note The permissions you pick in the Guild Install box only apply if your bot is invited to a guild, not for a user app!
24+
25+
If you have entered all the settings correctly the screen should look like the one below (except the **Administrator** permission - don't use this, enter actual permissions!):
26+
27+
\image html user_apps_1.png
28+
29+
# Inviting the application
30+
31+
You can now invite your bot to your profile. Follow the invite link at the top of the screen by clicking **copy** and pasting it into a web browser. You will be prompted
32+
to either add the bot to your profile, or to a guild, as shown below. Choose to add the bot to your profile:
33+
34+
\image html user_apps_2.png
35+
36+
You may be prompted to prove you are not a robot (you aren't a robot, right? 🤖). Afterwards, the bot will be successfully added to your profile:
37+
38+
\image html user_apps_3.png
39+
40+
# Creating the program
41+
42+
From this point on, right now, your bot will do nothing as you haven't added any code yet to make it operate as a user app. This comes next. Below is an example bot
43+
with one user application command.
44+
45+
There are several important things to note in this program:
46+
47+
* When adding a new slash command, you must use the dpp::slashcommand::set_interaction_contexts function to set where this command is visible. You can specify any
48+
one of three possible values to be added to the vector:
49+
* dpp::itc_guild: A standard slash command, visible in guild channels
50+
* dpp::itc_bot_dm: A standard slash command, accessible in DMs with the bot (this replaces the functionality of dpp::slashcommand::set_dm_permission)
51+
* dpp::itc_private_channel: A user application command, visible anywhere to the user who added it to their profile.
52+
* When responding to the slash command, most things remain the same, except of course if you reply to a user app command most things relating to the guild
53+
will be uninitialised default values. This is because there is no guild to reference.
54+
* You can use dpp::interaction::is_user_app_interaction() to determine if the interaction is initiated from a user app command, or a guild command.
55+
dpp::interaction::is_guild_interaction() does the inverse.
56+
* Calling dpp::interaction::get_authorizing_integration_owner() with the parameter value dpp::ait_user_install will give you the dpp::snowflake ID of the
57+
user who has the app added to their profile, if a user is currently executing a user app command. If you call this function when not in a user app context,
58+
you will get an uninitialised snowflake value instead.
59+
60+
## Example Program
61+
62+
\include{cpp} user_apps.cpp
63+
64+
# Testing
65+
66+
If all goes to plan, your new command will be accessible everywhere!
67+
68+
\image html user_apps_4.png

docpages/images/user_apps_1.png

110 KB
Loading

docpages/images/user_apps_2.png

222 KB
Loading

docpages/images/user_apps_3.png

109 KB
Loading

docpages/images/user_apps_4.png

199 KB
Loading

0 commit comments

Comments
 (0)