Skip to content
GitHub

getInstallContext

function in meocord/common Since 4.1.0

getInstallContext(interaction: BaseInteraction): InstallContext

Reports where an interaction happened and whether the bot is present there.

Use it in a handler a user-installed app runs: such an app can be used in servers the bot is not in, and in direct messages between users, where only the interaction's own methods (reply, editReply, followUp) reach the user.

Parameters

NameTypeDescription
interactionBaseInteraction

The interaction to inspect.

Returns

InstallContext

Where it happened, and whether the bot is present there.

Examples

TypeScript
@Command('rank', CommandType.SLASH)
async rank(interaction: ChatInputCommandInteraction) {
  const { where, botInstalled } = getInstallContext(interaction)
  // A user-installed command in a server without the bot: it can't read the server, so it answers privately
  if (where === 'guild' && !botInstalled) {
    await respond(interaction).send({ content: 'Add the bot to this server to see ranks.', flags: MessageFlags.Ephemeral })
  }
}