h1dr4x
h1dr4x
SIASapphire - Imagine a framework
Created by h1dr4x on 6/3/2023 in #sapphire-support
Type '"Rules"' is not assignable to type 'PreconditionEntryResolvable'.
Type '"Rules"' is not assignable to type 'PreconditionEntryResolvable'. src/preconditions/Rules.ts:
export class RulesPrecondition extends Precondition {
public constructor(context: PieceContext, options: PieceOptions) {
super(context, {
...options,
name: "Rules",
});
}
public override async messageRun(message: Message) {
const res = await this.checkUser(message.author.id);
if (res) return this.ok();
return this.error({
message: "You must accept the rules to use this command.",
});
}

private async checkUser(userId: string) {
const exists = await this.container.client.db.has(`user_${userId}`);
return exists;
}
}
export class RulesPrecondition extends Precondition {
public constructor(context: PieceContext, options: PieceOptions) {
super(context, {
...options,
name: "Rules",
});
}
public override async messageRun(message: Message) {
const res = await this.checkUser(message.author.id);
if (res) return this.ok();
return this.error({
message: "You must accept the rules to use this command.",
});
}

private async checkUser(userId: string) {
const exists = await this.container.client.db.has(`user_${userId}`);
return exists;
}
}
types/index.d.ts:
declare module "@sapphire/framework" {
interface SapphireClient {
db: PetDatabase;
}
interface Preconditions {
Rules: never;
}
}
declare module "@sapphire/framework" {
interface SapphireClient {
db: PetDatabase;
}
interface Preconditions {
Rules: never;
}
}
src/commands/ping.ts:
export class PingCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
name: "ping",
description: "ping pong",
preconditions: ["Rules"],
});
}
public async messageRun(message: Message) {
return message.channel.send(
`:ping_pong: | Pong! ${this.container.client.ws.ping}ms`
);
}
}
export class PingCommand extends Command {
public constructor(context: Command.Context, options: Command.Options) {
super(context, {
...options,
name: "ping",
description: "ping pong",
preconditions: ["Rules"],
});
}
public async messageRun(message: Message) {
return message.channel.send(
`:ping_pong: | Pong! ${this.container.client.ws.ping}ms`
);
}
}
discord.js v14.11.0 @sapphire/framework v4.4.4
12 replies