Closed zodiia closed 1 year ago
This doesn't help at all...
How am I supposed to create the handler that will receive these auto completion requests? The documentation doesn't say a word about this.
This doesn't help at all...
How am I supposed to create the handler that will receive these auto completion requests? The documentation doesn't say a word about this.
Read discord.js documentation, please
You don't understand. Please don't be like that, I read discord.js documentation many times, that's very much not the first time I create a discord bot.
However, the thing I was wondering was, since this project let us handle many things with custom handlers, decorators, ..., I was hoping there was something to handle autocompletion, since there is the @Handler
for the actual interaction.
If there isn't, I would have to handle it using a listener and check for the right command. That would be a very nice feature to have a @Autocomplete
or something like that, that you use in the same command class.
You don't understand. Please don't be like that, I read discord.js documentation many times, that's very much not the first time I create a discord bot.
However, the thing I was wondering was, since this project let us handle many things with custom handlers, decorators, ..., I was hoping there was something to handle autocompletion, since there is the
@Handler
for the actual interaction.If there isn't, I would have to handle it using a listener and check for the right command. That would be a very nice feature to have a
@Autocomplete
or something like that, that you use in the same command class.
I'm sorry, but i don't undersand what is @Autocomplete
decorator. There are many ways to handle autocomplete. If your logic is repeated, then you can put it in an interceptor
Here is an example:
A basic command with an argument can be implemented as such:
class TestCommandInteractionDto {
@Param({ description: 'Some argument', required: true, autocomplete: true })
arg: string
}
@Command({
name: 'test',
description: 'Do things',
})
export class TestCommand {
@Handler()
async onCommand(interaction: CommandInteraction, @IA(SlashCommandPipe) dto: TestCommandInteractionDto) {
return `Argument was ${dto.arg}`
}
}
What I was wondering was if something like that existed:
class TestCommandInteractionDto {
@Param({ description: 'Some argument', required: true, autocomplete: true })
arg: string
}
@Command({
name: 'test',
description: 'Do things',
})
export class TestCommand {
@Autocompletion()
async onAutocompletion(interaction: AutocompleteInteraction) { // argument type imported from discord.js
// Return a list of strings for autocompletion
}
@Handler()
async onCommand(interaction: CommandInteraction, @IA(SlashCommandPipe) dto: TestCommandInteractionDto) {
return `Argument was ${dto.arg}`
}
}
This way, managing autocompletion would be much easier than manually handling it using an event handler, manually checking which command is being autocompleted, and return the list accordingly.
When creating a slash command, there is an option to enable auto completion on a parameter (the
autocomplete
field in@Param
). However, there is no mention in the docs about how to actually implement this auto completion.Is there any way to implement it using this library, or do I have to manually handle
interactionCreate
events?Thank you!