getInstallContext
function in meocord/common Since 4.1.0
getInstallContext(interaction: BaseInteraction): InstallContextReports 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
| Name | Type | Description |
|---|---|---|
interaction | BaseInteraction | The interaction to inspect. |
Returns
InstallContextWhere it happened, and whether the bot is present there.
Examples
@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 })
}
}