Skip to content

@bight-ts/core — Preconditions

import {
definePrecondition,
createAdministratorPrecondition,
createGuildOnlyPrecondition,
createOwnerOnlyPrecondition,
createUserPermissionsPrecondition,
createDevelopmentOnlyPrecondition,
} from "@bight-ts/core";

Defines a custom precondition.

PropertyTypeRequiredDescription
namestringYesUnique name, referenced in command preconditions arrays
check(input: BightPreconditionExecution) => BightPreconditionCheckResultYesEvaluation function
PropertyTypeDescription
kindBightExecutionKind"command", "button", "modal", "select-menu", "message-command", or "prefix-command"
subjectBightExecutionSubjectThe interaction or message that triggered this check
interactionBightSupportedInteraction | undefinedPresent for interaction-based triggers
messageMessage | undefinedPresent for message-based triggers
contextBightContext<TServices>Your app context

Return one of:

  • true or void — allow
  • false — deny with default message
  • string — deny with custom message
  • { ok: boolean, message?: string } — explicit result
FunctionDefault nameOptions
createAdministratorPrecondition(options?)"administrator-only"name?, message?
createGuildOnlyPrecondition(options?)"guild-only"name?, message?, guildIds?: string[]
createOwnerOnlyPrecondition(options)"owner-only"ownerIds: string[], name?, message?
createUserPermissionsPrecondition(options)"required-user-permissions"permissions: PermissionResolvable[], name?, message?
createDevelopmentOnlyPrecondition(options)"development-only"isDevelopment: boolean, name?, message?

Passed to onDenied handlers.

PropertyTypeDescription
kindBightExecutionKindWhat type of execution was denied
subjectBightExecutionSubjectThe triggering interaction or message
contextBightContext<TServices>Your app context
reasonBightDeniedReasonDenial details (see below)
handledbooleanWhether a handler has already responded
reply(message?: string) => Promise<void>Send a denial response to the user
suppress() => voidSilently drop the denial with no user response
PropertyTypeDescription
code"development_only" | "missing_precondition" | "precondition_failed"Denial category
messagestringHuman-readable denial message
preconditionNamestring | undefinedName of the precondition that failed (if applicable)
  1. Global preconditions run first (registered via plugins).
  2. Local preconditions run second (attached to individual commands/handlers).
  3. If any precondition fails, execution halts and the onDenied handler (or default) runs.