Pitch
Pitch
SIASapphire - Imagine a framework
Created by Pitch on 2/26/2023 in #sapphire-support
Precondition with Slash Command
How to report precondition failure w/ clash command? If I use this.error({ message: 'error' }); in precondition, it does nothing.
import { Precondition } from '@sapphire/framework';
import config from '#rootJson/config' assert { type: 'json' };

export class OwnerOnlyPrecondition extends Precondition {
async messageRun(message) {
// for message command

return this.checkOwner(message.author.id);
}

async chatInputRun(interaction) {
return this.checkOwner(interaction.user.id);
}

async contextMenuRun(interaction) {
// for Context Menu Command

return this.checkOwner(interaction.user.id);
}

async checkOwner(userId) {
return config.owners.includes(userId) ? this.ok() : this.error({ message: 'Only the bot owner can use this command!' });
}
}
import { Precondition } from '@sapphire/framework';
import config from '#rootJson/config' assert { type: 'json' };

export class OwnerOnlyPrecondition extends Precondition {
async messageRun(message) {
// for message command

return this.checkOwner(message.author.id);
}

async chatInputRun(interaction) {
return this.checkOwner(interaction.user.id);
}

async contextMenuRun(interaction) {
// for Context Menu Command

return this.checkOwner(interaction.user.id);
}

async checkOwner(userId) {
return config.owners.includes(userId) ? this.ok() : this.error({ message: 'Only the bot owner can use this command!' });
}
}
6 replies