Cyber Grandma
Cyber Grandma
Explore posts from servers
SIASapphire - Imagine a framework
Created by Cyber Grandma on 11/9/2023 in #sapphire-support
Multiple listeners on the same event ?
Hi, I'm trying to define two listeners for the same event (chatInputCommandError) My folder is organised as such: src > listeners > commands > chatInputCommandError.ts chatInputCommandErrorBis.ts I want to handle some different types of errors in these two files. In these two files it's basically like so:
export class UserEvent extends Listener<typeof Events.ChatInputCommandError> {
public override async run(error: UserError, { interaction }: ChatInputCommandErrorPayload) {

if (Reflect.get(Object(error.context), 'silent')) return;
if (UserUsageError.isUserUsageError(error)) return; // If it's an error for the other file, return

// Do the stuff

}
}
export class UserEvent extends Listener<typeof Events.ChatInputCommandError> {
public override async run(error: UserError, { interaction }: ChatInputCommandErrorPayload) {

if (Reflect.get(Object(error.context), 'silent')) return;
if (UserUsageError.isUserUsageError(error)) return; // If it's an error for the other file, return

// Do the stuff

}
}
The issue is that the second file is never fired on errors, only the first one. What did I miss in the docs to make that work ? Thanks ❤️
4 replies
SIASapphire - Imagine a framework
Created by Cyber Grandma on 9/23/2023 in #sapphire-support
Type safe Slash Commands Options ?
Hi there, I can't seem to find a way to add Type Safe options to a Slash command. See Example:
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder //
.setName(this.name)
.setDescription(this.description)
.addStringOption((builder) => {
return builder
.setName('difficulty')
.setDescription('Choose a difficulty')
.addChoices({ name: 'Easy', value: 'easy' }, { name: 'Medium', value: 'medium' }, { name: 'Hard', value: 'hard' });
})
);
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder //
.setName(this.name)
.setDescription(this.description)
.addStringOption((builder) => {
return builder
.setName('difficulty')
.setDescription('Choose a difficulty')
.addChoices({ name: 'Easy', value: 'easy' }, { name: 'Medium', value: 'medium' }, { name: 'Hard', value: 'hard' });
})
);
}
I have a Type called type Difficulty = 'easy' | 'medium' | 'hard' and functions that expect this type. But the interaction.options.getString('difficulty', false) method simply returns string. Which means I need to add as Difficulty to it. And I feel like it defeats a little bit the purpose of TypeScript when I do this. So I was wondering if there was a better way to handle this, or should I just rely on Runtime checking ? Thanks ❤️
2 replies