Ignoring Precondition Failures

I'm working on a precondition that I wanna ignore on the ChatInputCommandDenied listener. The documentation suggests to a add information on the context in the Precondition
export class MyDummyPreconditions extends Precondition {
chatInputRun(
interaction: ChatInputCommandInteraction,
command: ChatInputCommand,
context: Precondition.Context
): Precondition.Result {
return this.error({ message: 'Ignored message', context: { silent: true } });
}
}
export class MyDummyPreconditions extends Precondition {
chatInputRun(
interaction: ChatInputCommandInteraction,
command: ChatInputCommand,
context: Precondition.Context
): Precondition.Result {
return this.error({ message: 'Ignored message', context: { silent: true } });
}
}
and check for it in ChatInputCommandDenied.
export class ChatInputCommandDeniedListener extends Listener<typeof Events.ChatInputCommandDenied> {
public async run({ context, message: content }: UserError, { interaction }: ChatInputCommandDeniedPayload) {
if (Reflect.get(Object(context), 'silent')) return;

if (interaction.deferred || interaction.replied) {
return interaction.editReply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] }
});
}

return interaction.reply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] },
ephemeral: true
});
}
}
export class ChatInputCommandDeniedListener extends Listener<typeof Events.ChatInputCommandDenied> {
public async run({ context, message: content }: UserError, { interaction }: ChatInputCommandDeniedPayload) {
if (Reflect.get(Object(context), 'silent')) return;

if (interaction.deferred || interaction.replied) {
return interaction.editReply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] }
});
}

return interaction.reply({
content,
allowedMentions: { users: [interaction.user.id], roles: [] },
ephemeral: true
});
}
}
That works but I realized that the interaction response will be:
The application did not respond
Is that expected or did I miss something?
Solution:
Only button ones can update a message with the same content and be fine
Jump to solution
7 Replies
Favna
Favna2y ago
you're not. Interactions have to be replied to. I never really thought about it but yeah the guide needs to be adjusted for that. Not sure what the proper fix would be. Not sure if interaction.reply() works... @Vladdy can interactions just be acknowledged but without an actual reply to the user?
vladdy
vladdy2y ago
no interactions NEED to send something
Solution
vladdy
vladdy2y ago
Only button ones can update a message with the same content and be fine
Favna
Favna2y ago
I suppose the least you can send then is a single zero width space but probably to just reply something then, but reply ephemeral so it's only visible to the user
Daniel Passos
Daniel PassosOP2y ago
Thanks that is what I’m doing just wanna check if the docs miss something
Favna
Favna2y ago
don't suppose you can make a PR to adjust that bit of text in the guide @danielpassos ? Would save me doing it haha
Daniel Passos
Daniel PassosOP2y ago
Will do!
Want results from more Discord servers?
Add your server