Skip to main content

Interface: Preconditions

The registered preconditions and their contexts, if any. When registering new ones, it is recommended to use module augmentation so custom ones are registered.

When a key's value is never, it means that it does not take any context, which allows you to pass its identifier as a bare string (e.g. preconditions: ['NSFW']), however, if context is required, a non-never type should be passed, which will type {@link PreconditionContainerArray#append} and require an object with the name and a context with the defined type.

example

declare module '@sapphire/framework' {
interface Preconditions {
// A precondition named `Moderator` which does not read `context`:
Moderator: never;

// A precondition named `ChannelPermissions` which does read `context`:
ChannelPermissions: {
permissions: Permissions;
};
}
}

// [✔] These are valid:
preconditions.append('Moderator');
preconditions.append({ name: 'Moderator' });
preconditions.append({
name: 'ChannelPermissions',
context: { permissions: new Permissions(8) }
});

// [X] These are invalid:
preconditions.append({ name: 'Moderator', context: {} });
// ➡ `never` keys do not accept `context`.

preconditions.append('ChannelPermissions');
// ➡ non-`never` keys always require `context`, a string cannot be used.

preconditions.append({
name: 'ChannelPermissions',
context: { unknownProperty: 1 }
});
// ➡ mismatching `context` properties, `{ unknownProperty: number }` is not
// assignable to `{ permissions: Permissions }`.

Properties

ClientPermissions

ClientPermissions: Object

Type declaration

NameType
permissionsPermissions

Defined in

projects/framework/src/lib/structures/Precondition.ts:120


Cooldown

Cooldown: CooldownPreconditionContext

Defined in

projects/framework/src/lib/structures/Precondition.ts:109


DMOnly

DMOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:110


Enabled

Enabled: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:111


GuildNewsOnly

GuildNewsOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:112


GuildNewsThreadOnly

GuildNewsThreadOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:113


GuildOnly

GuildOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:114


GuildPrivateThreadOnly

GuildPrivateThreadOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:115


GuildPublicThreadOnly

GuildPublicThreadOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:116


GuildTextOnly

GuildTextOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:117


GuildThreadOnly

GuildThreadOnly: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:118


NSFW

NSFW: never

Defined in

projects/framework/src/lib/structures/Precondition.ts:119


UserPermissions

UserPermissions: Object

Type declaration

NameType
permissionsPermissions

Defined in

projects/framework/src/lib/structures/Precondition.ts:123