[ERROR] Encountered error on event listener "CorePreChatInputCommandRun"

I'm getting this error repeatedly on an OwnerOnly precondition:
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js" TypeError: Cannot read properties of undefined (reading 'isErr')
at Object.chatInputSequential (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/utils/preconditions/conditions/PreconditionConditionAnd.js:22:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async CoreListener.run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js:19:25)
at async Object.fromAsync (/home/effem/effem.dev/COREBot/node_modules/@sapphire/result/dist/index.js:613:22)
at async CoreListener._run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/structures/Listener.js:48:22)
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js" TypeError: Cannot read properties of undefined (reading 'isErr')
at Object.chatInputSequential (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/utils/preconditions/conditions/PreconditionConditionAnd.js:22:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async CoreListener.run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js:19:25)
at async Object.fromAsync (/home/effem/effem.dev/COREBot/node_modules/@sapphire/result/dist/index.js:613:22)
at async CoreListener._run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/structures/Listener.js:48:22)
Solution:
you need to return this.error
Jump to solution
3 Replies
FM
FMOP2mo ago
I'm getting this error on an OwnerOnly precondition check:
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js" TypeError: Cannot read properties of undefined (reading 'isErr')
at Object.chatInputSequential (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/utils/preconditions/conditions/PreconditionConditionAnd.js:22:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async CoreListener.run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js:19:25)
at async Object.fromAsync (/home/effem/effem.dev/COREBot/node_modules/@sapphire/result/dist/index.js:613:22)
at async CoreListener._run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/structures/Listener.js:48:22)
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js" TypeError: Cannot read properties of undefined (reading 'isErr')
at Object.chatInputSequential (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/utils/preconditions/conditions/PreconditionConditionAnd.js:22:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async CoreListener.run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js:19:25)
at async Object.fromAsync (/home/effem/effem.dev/COREBot/node_modules/@sapphire/result/dist/index.js:613:22)
at async CoreListener._run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/structures/Listener.js:48:22)
The precondition works, but this error populates when a not-owner uses the command. Precondition code in the following reply. This is the OwnerOnly precondition, very close to what's demonstrated in the guide:
import { Precondition } from "@sapphire/framework";

let returnMessageObj = {
content: 'gotta be the server owner to use this, my friend.',
ephemeral: true
};

export class OwnerOnlyPrecondition extends Precondition {

async chatInputRun(interaction) {
// for Slash Commands
return this.checkOwner(interaction.user.id, interaction);
}

async checkOwner(userID, interaction) {
if (process.env.DISCORD_BOT_OWNER === userID) {
return this.ok();
} else {
interaction.reply(returnMessageObj);
this.error({ message: 'Only the bot owner can use this command!' });
}
}
}
import { Precondition } from "@sapphire/framework";

let returnMessageObj = {
content: 'gotta be the server owner to use this, my friend.',
ephemeral: true
};

export class OwnerOnlyPrecondition extends Precondition {

async chatInputRun(interaction) {
// for Slash Commands
return this.checkOwner(interaction.user.id, interaction);
}

async checkOwner(userID, interaction) {
if (process.env.DISCORD_BOT_OWNER === userID) {
return this.ok();
} else {
interaction.reply(returnMessageObj);
this.error({ message: 'Only the bot owner can use this command!' });
}
}
}
Everything works ... just, as mentioned before, the error spits when the command this is currently used with (Ping) is executed by a not-owner. This leaves me scratching my head. I've poured over the docs, glanced at the source. I don't know what I'm missing. Any help is appreciated!
Solution
Favna
Favna2mo ago
you need to return this.error
FM
FMOP2mo ago
🤦‍♂️ Why is it that the things I struggle with the most have such a simple--and often overlooked--solution? Thank you. That fixed it.
Want results from more Discord servers?
Add your server