arguments

how to make arguments throw error when smh is not filled for ex !prefix set - but the prefix is required
Solution:
found it, i was using wrong event. correct event: subcommand error
Jump to solution
23 Replies
feenek
feenekOP17mo ago
i dont know if i explained it correctly lmao
import { ApplyOptions } from '@sapphire/decorators';
import { Events, Listener, UserError, type MessageCommandDeniedPayload } from '@sapphire/framework';

@ApplyOptions<Listener.Options>({
event: Events.MessageCommandDenied
})
export class UserEvent extends Listener {
public async run({ context: _context, message: content }: UserError, { message }: MessageCommandDeniedPayload) {
console.log('MessageCommandDenied')
message.reply({
content: content
});
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Events, Listener, UserError, type MessageCommandDeniedPayload } from '@sapphire/framework';

@ApplyOptions<Listener.Options>({
event: Events.MessageCommandDenied
})
export class UserEvent extends Listener {
public async run({ context: _context, message: content }: UserError, { message }: MessageCommandDeniedPayload) {
console.log('MessageCommandDenied')
message.reply({
content: content
});
}
}
this thing doesnt even emits i tought its gonna be it but no or im doing it wrong
Favna
Favna17mo ago
MessageCommandDenied is for preconditions, not arguments errors. You catch argument errors in MessageCommandError. The full list of events can be found here: https://www.sapphirejs.dev/docs/Documentation/api-framework/#events And you can also reference other bots that already use Sapphire:
Spinel
Spinel17mo ago
Discord bots that use @sapphire/framework v4 - Official Bot Examples ᴱ ᴰ ᴶˢ - Gemboard ᴱ ᴰ - Dragonite ᴱ ᴰ - Radon ᴱ ᴬ - Sapphire Application Commands Examples ᴱ - Archangel ᴱ ᴰ - Zeyr ᴰ ᴬ - Birthdayy ᴰ - KBot ᴱ ᴬ ᴰ Discord bots that use @sapphire/framework v3 - Arima ᴱ - Nino ᴱ ᴰ - Operator ᴱ ᴬ ᴰ - Spectera ᴬ Discord bots that use @sapphire/framework v2 - Materia ᴱ - RTByte ᴱ ᴬ - Skyra ᴬ ᴰ - YliasDiscordBot ᴬ : Uses ESM (if not specified then uses CJS) : Advanced bot (if not specified it is a simple bot, or not graded) : Uses Docker in production ᴶˢ: Written in JavaScript. If not specified then the bot is written in TypeScript.
feenek
feenekOP17mo ago
umm still not working
import { ApplyOptions } from '@sapphire/decorators';
import { Listener, type MessageCommandErrorPayload, UserError } from '@sapphire/framework';
import { reply } from '@sapphire/plugin-editable-commands';
import { Events } from '@sapphire/framework';

@ApplyOptions<Listener.Options>({
event: Events.MessageCommandError
})
export class UserListener extends Listener {
public override async run(error: UserError, { message }: MessageCommandErrorPayload) {
return reply(message, {
content: error.message
});
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Listener, type MessageCommandErrorPayload, UserError } from '@sapphire/framework';
import { reply } from '@sapphire/plugin-editable-commands';
import { Events } from '@sapphire/framework';

@ApplyOptions<Listener.Options>({
event: Events.MessageCommandError
})
export class UserListener extends Listener {
public override async run(error: UserError, { message }: MessageCommandErrorPayload) {
return reply(message, {
content: error.message
});
}
}
feenek
feenekOP17mo ago
feenek
feenekOP17mo ago
feenek
feenekOP17mo ago
the command is working but the args error doesnt shows up okay i debugged this code and it seems the listener is loaded but it doesnt fires idk why
Solution
feenek
feenek17mo ago
found it, i was using wrong event. correct event: subcommand error
feenek
feenekOP17mo ago
how to make subcommand/command custom property like this (this is not valid but i want it to be)
feenek
feenekOP17mo ago
nvm solved but now i have question how to: 1. handle permissions (custom responses etc) 2. handle cooldowns (custom respnose)
Favna
Favna17mo ago
Use detailedDescription.usage. DetailedDescription is an interface you can augment. Listen for the precondition denied event, identify the error with error.identifier, and use the error.context to get the data of the violation (available for both of these) and then you can send a custom reply from the listener.
feenek
feenekOP17mo ago
ty
feenek
feenekOP17mo ago
how to import this event, i dont see event named like this nvm i got it another issue i've got
feenek
feenekOP17mo ago
feenek
feenekOP17mo ago
and this
feenek
feenekOP17mo ago
feenek
feenekOP17mo ago
it doesnt even logs limit
Favna
Favna17mo ago
You really should just use the built in cooldown... Error is pretty clear I'd say but maybe you should just start over and use @sapphire/cli to generate a project because if you falter at configuring typescript config you're really gonna have many many many issues down the road
Favna
Favna17mo ago
Favna
Favna17mo ago
Sapphire Framework
Getting started with Sapphire | Sapphire
To install Sapphire, you need to install both discord.js and
Favna
Favna17mo ago
And you'd also do well reading the DiscordJS guide https://discordjs.guide/#before-you-begin
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Favna
Favna17mo ago
OP left server so closing thread
Want results from more Discord servers?
Add your server