BotNetwork

Discord user-installable apps: integration_types and contexts explained

Discord apps are no longer limited to servers. A user can install your app to their own account and run its commands in any server, in DMs and in group DMs. Two fields on each command control where that is allowed, and two fields on each interaction tell you where you are.

Published 7 min read

Two installation contexts

Discord's documentation calls the place where an app is installed its installation context. There are two, identified by integration type IDs:

  • GUILD_INSTALL (0): the app is installed to a server. A member with the MANAGE_GUILD permission must authorize it, it is visible to everyone in that server, and it usually comes with a bot user and a set of permissions.
  • USER_INSTALL (1): the app is installed to a user account. It is visible only to the user who authorized it, but across all of that user's servers, DMs and group DMs.

According to the Application resource documentation, newly created apps only support server installation by default. A user-installed app does not join any server, so it cannot take actions there the way a bot user can, and it must respect the permissions of the person using it in that channel.

When a user install makes sense

User installs fit personal utilities: lookups, converters, a /profile card for a game account, a "save this message" context menu, or a quick formatter. The user brings the tool with them instead of asking every server admin to add a bot. Features that manage a community, such as moderation, welcome messages or a server leaderboard, still belong to a server install, where an admin has granted explicit permissions. Many apps support both and decide per command.

Enabling User Install in the Developer Portal

  1. Open your application in the Developer Portal and go to the Installation page.
  2. Under Installation Contexts, enable User Install in addition to (or instead of) Guild Install.
  3. Under Install Link, Discord recommends the Discord Provided Link for most apps. It asks the user which way to install when both contexts are enabled.
  4. In Default Install Settings, give User Install the applications.commands scope. Discord's tutorial notes that, at the moment, user installs only support that scope in the default settings. Guild Install usually gets applications.commands plus bot with the permissions you need, following the same least-privilege idea as narrow Discord invite URLs.

If you build your own OAuth2 authorize URL instead, the integration_type query parameter selects the context (0 for server, 1 for user), and it only matters when the scope includes applications.commands.

Enabling a new context does not change existing commands. The documentation is explicit: you must update your commands if you want them available in the new context.

Two fields on every command

Global application commands have two context fields:

  • integration_types: the installation contexts in which the command exists (0, 1 or both). A value is only accepted if the app supports that context at the application level.
  • contexts: the surfaces where the command can be used. GUILD (0) is a server channel, BOT_DM (1) is the DM with your app's bot user, and PRIVATE_CHANNEL (2) is any other DM or a group DM.

Three rules from the docs save debugging time:

  • Both fields apply only to global commands. Guild-scoped commands, the ones that are handy while testing (see guild commands while building), do not support the BOT_DM context.
  • PRIVATE_CHANNEL is only meaningful when integration_types includes USER_INSTALL. A server-installed bot cannot run in a DM between two other people.
  • These contexts are separate from command permissions inside a server. default_member_permissions still controls who may run a command where the app is server-installed.

Do not rely on defaults. The API reference describes default values that differ between endpoints, so set both fields explicitly on every command you register.

Registering commands with discord.js

discord.js v14 exposes both fields on SlashCommandBuilder. This was checked against discord.js 14.28.1 at the time of writing; the builder output is the JSON shown in the comment:

const {
  SlashCommandBuilder, ApplicationIntegrationType, InteractionContextType,
} = require('discord.js');

// Works for server and user installs, in every surface.
const lookup = new SlashCommandBuilder()
  .setName('lookup')
  .setDescription('Look up a term in the docs')
  .addStringOption(o => o.setName('term').setDescription('Term').setRequired(true))
  .setIntegrationTypes(ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall)
  .setContexts(InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel);
// -> "integration_types": [0, 1], "contexts": [0, 1, 2]

// Community feature: only where an admin installed the app, only in servers.
const leaderboard = new SlashCommandBuilder()
  .setName('leaderboard')
  .setDescription('Show this server\'s leaderboard')
  .setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
  .setContexts(InteractionContextType.Guild);

Register them as global commands with the REST client (Routes.applicationCommands(clientId)), exactly as in slash commands in discord.js v14. Without discord.js, send the same integration_types and contexts arrays in the JSON body of PUT /applications/<application_id>/commands.

Reading the context of an interaction

Each interaction tells you where it happened through two fields:

  • context: the interaction context type (0, 1 or 2) where it was triggered.
  • authorizing_integration_owners: a map keyed by installation context. For GUILD_INSTALL ("0") the value is the server ID, or "0" when the interaction comes from the DM with your bot user. For USER_INSTALL ("1") the value is the ID of the user who installed the app. A key only appears when the app is authorized in that context and the command supports it.

Together they answer the practical question: is my bot actually in this server? If the map only has USER_INSTALL while context is GUILD, the user brought your app into a server where it is not installed. The interaction also carries app_permissions, the permissions your app has in that location, which is worth checking before you try anything beyond a reply.

In discord.js these are interaction.context and interaction.authorizingIntegrationOwners (with guildId and userId properties):

const { Events, InteractionContextType, MessageFlags } = require('discord.js');

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand() || interaction.commandName !== 'lookup') return;

  const owners = interaction.authorizingIntegrationOwners;
  const inServer = interaction.context === InteractionContextType.Guild;
  const serverInstalled = inServer && owners.guildId !== null && owners.guildId !== '0';

  // Public reply only in the DM with the bot; everywhere else, only the user sees it.
  const isBotDm = interaction.context === InteractionContextType.BotDM;
  const term = interaction.options.getString('term', true);

  await interaction.reply({
    content: `Result for "${term}" (server install here: ${serverInstalled ? 'yes' : 'no'})`,
    flags: isBotDm ? undefined : MessageFlags.Ephemeral,
  });
});

The same logic works for an HTTP endpoint; read context and authorizing_integration_owners from the JSON body after verifying the signature, as described in Discord interactions over HTTP.

Responding without surprises

  • Prefer ephemeral replies outside the bot DM. Discord's own tutorial makes /profile ephemeral when it runs in a server or a group DM and adds a button so the user can choose to share it. That respects people who never installed your app.
  • Expect missing permissions. User-installed apps follow the invoking user's permissions. If the user cannot send messages in a channel, a non-ephemeral response will not be possible there.
  • Count follow-ups. When an interaction comes from a user-installed app that is not installed in the server (only USER_INSTALL in the owners map), Discord limits it to 5 follow-up messages per interaction.
  • Keep the 3-second rule. As with any interaction, send an initial response within 3 seconds or defer; the token then works for 15 minutes.
  • Do not assume server data. Without a server install there is no bot member, so guild endpoints and Gateway events for that server are not available to you.

Privacy, terms and a home for your app

A user-installed app can be invoked in conversations with people who never agreed to it, so it is worth publishing clear documentation: what each command does, what data it stores and how to delete it (a /privacy command helps too). The application object has fields for a Terms of Service URL and a Privacy Policy URL, and both point to pages you host. A short domain from Namecheap domains makes those links easy to trust, and a small static site on Namecheap hosting is enough for docs, terms and a privacy page. If your bot also uses an HTTPS interactions endpoint, Namecheap lets you keep the domain and site in one account while the endpoint runs on a subdomain, as covered in a custom domain and HTTPS for your bot.

Checklist

  1. Enable User Install on the Installation page and give it the applications.commands scope.
  2. Decide, per command, whether it is a personal tool, a community feature or both.
  3. Set integration_types and contexts explicitly on every global command and register them again.
  4. Use PRIVATE_CHANNEL only for commands that include USER_INSTALL.
  5. In handlers, read context, authorizing_integration_owners and app_permissions before acting.
  6. Reply ephemerally outside the bot DM unless the user chooses to share.
  7. Respect the 3-second deadline and the 5 follow-up limit for user-only installs.
  8. Publish documentation, terms and a privacy policy, and link them in the Developer Portal.

Sources