Having trouble with reporting precondition failure

I am trying to send an error message when a person who isnt the bot owner runs the eval command but i cant get it to work I followed the docs and even copied the example bot but nothing seems to make the thing work. I tried to console.log error.message but that doesnt console.log either Precondition
// OwnerOnly.ts
import { Precondition } from '@sapphire/framework';
import type { Message } from 'discord.js';

export class OwnerOnlyPrecondition extends Precondition {
public override async messageRun(message: Message) {
// for Message Commands
return this.checkOwner(message.author.id);
}

private async checkOwner(userId: string) {
return userId === '600707283097485322'
? this.ok()
: this.error({ message: 'Only the bot owner can use this command!' });
}
}

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

export default undefined
// OwnerOnly.ts
import { Precondition } from '@sapphire/framework';
import type { Message } from 'discord.js';

export class OwnerOnlyPrecondition extends Precondition {
public override async messageRun(message: Message) {
// for Message Commands
return this.checkOwner(message.author.id);
}

private async checkOwner(userId: string) {
return userId === '600707283097485322'
? this.ok()
: this.error({ message: 'Only the bot owner can use this command!' });
}
}

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

export default undefined
Listener
// messageCommmandDenied.ts
import type { Events, MessageCommandDeniedPayload } from '@sapphire/framework';
import { Listener, UserError } from '@sapphire/framework';

export class UserEvent extends Listener<typeof Events.MessageCommandDenied> {
public async run(
{ message: content }: UserError,
{ message }: MessageCommandDeniedPayload
) {
// `context: { silent: true }` should make UserError silent:
// Use cases for this are for example permissions error when running the `eval` command.
console.log(content);
return message.channel.send({
content,
allowedMentions: { users: [message.author.id], roles: [] },
});
}
}
// messageCommmandDenied.ts
import type { Events, MessageCommandDeniedPayload } from '@sapphire/framework';
import { Listener, UserError } from '@sapphire/framework';

export class UserEvent extends Listener<typeof Events.MessageCommandDenied> {
public async run(
{ message: content }: UserError,
{ message }: MessageCommandDeniedPayload
) {
// `context: { silent: true }` should make UserError silent:
// Use cases for this are for example permissions error when running the `eval` command.
console.log(content);
return message.channel.send({
content,
allowedMentions: { users: [message.author.id], roles: [] },
});
}
}
12 Replies
Oreo ™
Oreo ™OP2y ago
I tried removing the
declare module '@sapphire/framework' {
interface Preconditions {
OwnerOnly: never;
}
}

export default undefined
declare module '@sapphire/framework' {
interface Preconditions {
OwnerOnly: never;
}
}

export default undefined
part and placing it inside a index.d.ts file but then the eval command has the error Type '"OwnerOnly"' is not assignable to type 'PreconditionEntryResolvable' what do i do
kyra
kyra2y ago
Remove the export default It's conflicting with the class export
Oreo ™
Oreo ™OP2y ago
Now it stops the command from being executed but it still doesnt send the error message
kyra
kyra2y ago
Does it log in the listener?
Oreo ™
Oreo ™OP2y ago
i dont think so no
Favna
Favna2y ago
1. Name of the listener file? 2. Are you actually using message commands and not chat input or context menu commands? They have their own listeners.
Oreo ™
Oreo ™OP2y ago
1. messageCommandDenied.ts 2. yes i am sure
kyra
kyra2y ago
Where is the listener at? In which folder?
Oreo ™
Oreo ™OP2y ago
src/listener/commands/messageCommands
Favna
Favna2y ago
It should be listeners plural src/listeners/commands/messageCommands
Oreo ™
Oreo ™OP2y ago
I set it to this and it still doesnt work
Oreo ™
Oreo ™OP2y ago
other listeners such as memberGuildAdd events works only this one doesnt it was very simple actually
@ApplyOptions<Listener.Options>({
event: Events.MessageCommandDenied,
})
@ApplyOptions<Listener.Options>({
event: Events.MessageCommandDenied,
})
idk why it doesnt say to add that in the docs but it worked
Want results from more Discord servers?
Add your server