User Installable Applications
Hello!
This post is all about User Installable Applications and how to set them up.
Let’s get into the hows and whats, as well as limitations.
Additions/edits to existing methods to accomodate this. #
Discord.py always like to be convenient for it’s userbase, and as such we’ve correctly modified the following items:-
Edits/Changes #
@app_commands.dm_only()
- Applies the
dms=True
to the command allowed contexts.
- Applies the
@app_commands.guild_only()
- Applies the
guilds=True
to the command allowed contexts.
- Applies the
Added #
@app_commands.private_channel_only()
- Applies the
private_channels=True
to allowed contexts.
- Applies the
@app_commands.guild_install()
- Specifies that this command will be a guild installable application command.
@app_commands.user_install()
- Specifies that this command will be a user installable application command.
@allowed_installs()
- Controls the allowed installation methods.
@allowed_contexts()
- Controls the allowed installation contexts.
Interaction.is_user_integration()
- Determines if the interaction came from a user installed command.
Interaction.is_guild_integration()
- Determines if the interaction came from a guild installed command.
Install locations #
There are limited places where you can “install” these commands. These are:-
- Per User (you)
- Per Guild (which you manage)
“Per User” means that you can install an application to your user profile, which you - and only you - can use. You can use this in any guild, any channel, any DM, so long as it allowed in the context.
“Per Guild” means you can install an application within a guild which you have the Manage Guild permission in. Anyone in this guild can use this application command, so long as:-
- It is in the allowed context.
- They have permission to execute these commands as per the usual Application Command permissions.
Allowed contexts #
Contexts are where installed apps are allowed to be used. In essence, the developer can specify where their commands are allowed to be used. Currently this is limited to:-
- Guilds
- DMs
- Private Channels (Group DMs/chats)
For some added clarity, let’s imagine the below scenarios and how they work:-
Developer creates a user-installable application with allowed contexts of guilds and dms.
This means that a general user can install this application to their account for their personal use, but they cannot use this application within a group chat or group dm. Only within guilds and DMs.
Developer creates a user-installable application with allowed context of private channels.
This means that a general user can install this application to their account for their personal use, but they can only use this application within a group chat/dm.
Developer creates a guild and user installable application with the allowed context of guilds.
This means that a Guild manager or general user can install this command - Guild managers require the Manage Guild permission to install applications - and general users can install it to their account for usage. This application can only be used within guilds.
Creating installable commands #
Note: I will be using explicit definitions in decorators to show all options, but you as a user can allow the defaults.
Slash - user installable, executable anywhere. #
Let’s define a command that says hello to the executing user, and make it user installable, but executable anywhere.
You can see that using the decorators above is how we define the restrictions on user installable apps. Once your command is defined you’d sync it as normal to make the changes live.
Slash - guild installable, executable only in guilds. #
Now we’ll define a command that can be installed to, and only used within a guild. Something like a member info command:-
ContextMenu - user, non-cog, user installable, executable in dms and private channels #
What a title… Anyway, let’s get to it.
This is a lazy example, sorry, but you can see the decorators in use here as expected.
ContextMenu - cog, user installable, all contexts #
These titles are getting crazy. This example is gonna be way more wordy, purely because of the Bot + Cog boilerplate code. But the example will be relevant.
This example is very wordy, but it was to show the allowed_contexts
and allowed_installs
kwargs in the ContextMenu
constructor. This is how you’d do this, in this specific context.
Here’s the relevant documentation for all 3 items:-
Things to keep in mind. #
Permissions #
If an application is installed both to your user and the current guild you’re using it in, then guild permissions may override your ability to use your user installed commands from the application.
Available information #
When using processing a user installed command, the only information available to you is what’s contained on the interaction itself. You will not receive any extra information that you may be used to having such as guild members, guild roles, etc.
Final notes #
As always, don’t forget to sync as normal to make your apps installable after code changes, and don’t forget to join discord.py if you need more help.