bonk
bonk
SIASapphire - Imagine a framework
Created by bonk on 10/10/2023 in #sapphire-support
OwnerOnly precondition not working
Hello there. I just yoinked the OwnerOnly precondition from the guide and the Github repo but I just can't make it work. I don't get an error, I also yoinked the precondition failure messages, I don't get any info about why its not working. I only get "The application did not respond". Without the precondition my command works. OwnerOnly.ts
import { Precondition } from '@sapphire/framework';

import type {
CommandInteraction,
ContextMenuCommandInteraction,
Message,
Snowflake,
} from 'discord.js';

export class UserPrecondition extends Precondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return userId === '447000659871662081'
? this.ok()
: this.error({ message: this.#message });
}
}

declare module '@sapphire/framework' {
interface Preconditions {
OwnerOnly: never;
}
}
import { Precondition } from '@sapphire/framework';

import type {
CommandInteraction,
ContextMenuCommandInteraction,
Message,
Snowflake,
} from 'discord.js';

export class UserPrecondition extends Precondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return userId === '447000659871662081'
? this.ok()
: this.error({ message: this.#message });
}
}

declare module '@sapphire/framework' {
interface Preconditions {
OwnerOnly: never;
}
}
10 replies