File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ import {
29
29
registerCommands ,
30
30
registerButtons ,
31
31
registerModals ,
32
- registerSelectMenus
32
+ registerSelectMenus ,
33
+ registerAutocomplete
33
34
} from './register'
34
35
import {
35
36
resolveButton ,
@@ -130,6 +131,7 @@ export const createHarmonix = async (
130
131
registerButtons ( harmonix )
131
132
registerModals ( harmonix )
132
133
registerSelectMenus ( harmonix )
134
+ registerAutocomplete ( harmonix )
133
135
134
136
return harmonix
135
137
}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { ClientEvents, Events } from 'discord.js'
2
2
import consola from 'consola'
3
3
import { colors } from 'consola/utils'
4
4
import { resolveOption } from './utils'
5
- import { ctx } from './harmonix'
5
+ import { createError , ctx } from './harmonix'
6
6
import type { Harmonix , ParsedInputs , ParsedOptions } from './types'
7
7
8
8
export const registerEvents = ( harmonix : Harmonix ) => {
@@ -143,3 +143,17 @@ export const registerSelectMenus = (harmonix: Harmonix) => {
143
143
slm . callback ( interaction )
144
144
} )
145
145
}
146
+
147
+ export const registerAutocomplete = ( harmonix : Harmonix ) => {
148
+ harmonix . client ?. on ( Events . InteractionCreate , async ( interaction ) => {
149
+ if ( ! interaction . isAutocomplete ( ) ) return
150
+ const cmd = harmonix . commands . get ( interaction . commandName )
151
+
152
+ if ( ! cmd || ! cmd . config . autocomplete ) return
153
+ try {
154
+ await cmd . config . autocomplete ( interaction )
155
+ } catch ( error : any ) {
156
+ createError ( error . message )
157
+ }
158
+ } )
159
+ }
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ import type {
9
9
APIInteractionDataResolvedChannel ,
10
10
GuildMember ,
11
11
APIInteractionDataResolvedGuildMember ,
12
- Attachment
12
+ Attachment ,
13
+ AutocompleteInteraction
13
14
} from 'discord.js'
14
15
15
16
type OptionType =
@@ -28,7 +29,9 @@ type _OptionDef<T extends OptionType> = {
28
29
description ?: string
29
30
required ?: boolean
30
31
metadata ?: Record < string , any >
31
- }
32
+ } & ( T extends 'String' | 'Integer' | 'Number'
33
+ ? { autocomplete ?: boolean }
34
+ : { } )
32
35
33
36
type StringOptionDef = _OptionDef < 'String' >
34
37
type IntegerOptionDef = _OptionDef < 'Integer' >
@@ -170,6 +173,7 @@ export interface CommandConfig<T extends OptionsDef = OptionsDef> {
170
173
userPermissions ?: PermissionsString [ ]
171
174
preconditions ?: string [ ]
172
175
dm ?: boolean
176
+ autocomplete ?: ( interaction : AutocompleteInteraction ) => Promise < void > | void
173
177
}
174
178
175
179
export type CommandExecute < T extends OptionsDef = OptionsDef > = (
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ export const slashToJSON = (cmd: HarmonixCommand<OptionsDef>) => {
37
37
. setName ( name )
38
38
. setDescription ( arg . description ?? 'No description provided' )
39
39
. setRequired ( arg . required ?? true )
40
+ . setAutocomplete ( arg . autocomplete ?? false )
40
41
41
42
if ( arg . metadata ?. minLength ) {
42
43
opt . setMinLength ( arg . metadata . minLength )
@@ -60,6 +61,7 @@ export const slashToJSON = (cmd: HarmonixCommand<OptionsDef>) => {
60
61
. setName ( name )
61
62
. setDescription ( arg . description ?? 'No description provided' )
62
63
. setRequired ( arg . required ?? true )
64
+ . setAutocomplete ( arg . autocomplete ?? false )
63
65
64
66
if ( arg . metadata ?. minValue ) {
65
67
opt . setMinValue ( arg . metadata . minValue )
@@ -123,6 +125,7 @@ export const slashToJSON = (cmd: HarmonixCommand<OptionsDef>) => {
123
125
. setName ( name )
124
126
. setDescription ( arg . description ?? 'No description provided' )
125
127
. setRequired ( arg . required ?? true )
128
+ . setAutocomplete ( arg . autocomplete ?? false )
126
129
127
130
if ( arg . metadata ?. minValue ) {
128
131
opt . setMinValue ( arg . metadata . minValue )
You can’t perform that action at this time.
0 commit comments