@@ -4,17 +4,13 @@ import {
44 ChatInputCommandInteraction ,
55 ContextMenuCommandBuilder ,
66 PermissionFlagsBits ,
7- SlashCommandBuilder ,
8- channelMention ,
9- roleMention ,
10- userMention ,
11- type User
7+ SlashCommandBuilder
128} from 'discord.js'
139import type {
1410 HarmonixCommand ,
1511 HarmonixContextMenu ,
16- OptionType ,
17- OptionsDef
12+ OptionsDef ,
13+ ParsedOptionType
1814} from './types'
1915
2016export const slashToJSON = ( cmd : HarmonixCommand < OptionsDef > ) => {
@@ -143,6 +139,22 @@ export const slashToJSON = (cmd: HarmonixCommand<OptionsDef>) => {
143139 return opt
144140 } )
145141 break
142+ case 'Mentionable' :
143+ builder . addMentionableOption ( ( opt ) =>
144+ opt
145+ . setName ( name )
146+ . setDescription ( arg . description ?? 'No description provided' )
147+ . setRequired ( arg . required ?? true )
148+ )
149+ break
150+ case 'Attachment' :
151+ builder . addAttachmentOption ( ( opt ) =>
152+ opt
153+ . setName ( name )
154+ . setDescription ( arg . description ?? 'No description provided' )
155+ . setRequired ( arg . required ?? true )
156+ )
157+ break
146158 }
147159 }
148160 }
@@ -176,87 +188,30 @@ export const isHarmonixCommand = (
176188 return ( command as HarmonixCommand < OptionsDef > ) . config . category !== undefined
177189}
178190
179- export const resolveOption = async (
180- interaction : ChatInputCommandInteraction ,
181- type : OptionType | null ,
182- value : string
183- ) => {
184- switch ( type ) {
185- case 'String' :
186- return value
187- case 'Integer' :
188- return parseInt ( value )
189- case 'Boolean' :
190- return value === 'true'
191- case 'User' :
192- const user = await resolveUser ( interaction , value )
193-
194- return user
195- case 'Channel' :
196- const channel = await resolveChannel ( interaction , value )
197-
198- return channel
199- case 'Role' :
200- const role = await resolveRole ( interaction , value )
201-
202- return role
203- case 'Number' :
204- return parseFloat ( value )
205- }
206- }
207-
208- const resolveUser = async (
209- interaction : ChatInputCommandInteraction ,
210- value : string
211- ) : Promise < User | undefined > => {
212- return interaction . guild ?. members . cache . find (
213- ( member ) =>
214- member . user . username === value ||
215- member . nickname === value ||
216- member . id === value ||
217- userMention ( member . id ) === value ||
218- `<@!${ member . id } >` === value
219- ) ?. user
220- }
221-
222- const resolveChannel = async (
191+ export const resolveOption = (
223192 interaction : ChatInputCommandInteraction ,
224- value : string
225- ) => {
226- return interaction . guild ?. channels . cache . find (
227- ( channel ) =>
228- channel . name === value ||
229- channel . id === value ||
230- channelMention ( channel . id ) === value
231- )
232- }
233-
234- const resolveRole = async (
235- interaction : ChatInputCommandInteraction ,
236- value : string
237- ) => {
238- return interaction . guild ?. roles . cache . find (
239- ( role ) =>
240- role . name === value || role . id === value || roleMention ( role . id ) === value
241- )
242- }
243-
244- export const toOption = ( type : ApplicationCommandOptionType | null ) => {
193+ type : ApplicationCommandOptionType ,
194+ name : string
195+ ) : ParsedOptionType => {
245196 switch ( type ) {
246197 case ApplicationCommandOptionType . String :
247- return 'String'
198+ return interaction . options . getString ( name )
248199 case ApplicationCommandOptionType . Integer :
249- return 'Integer'
200+ return interaction . options . getInteger ( name )
250201 case ApplicationCommandOptionType . Boolean :
251- return 'Boolean'
202+ return interaction . options . getBoolean ( name )
252203 case ApplicationCommandOptionType . User :
253- return 'User'
204+ return interaction . options . getUser ( name )
254205 case ApplicationCommandOptionType . Channel :
255- return 'Channel'
206+ return interaction . options . getChannel ( name )
256207 case ApplicationCommandOptionType . Role :
257- return 'Role'
208+ return interaction . options . getRole ( name )
258209 case ApplicationCommandOptionType . Number :
259- return 'Number'
210+ return interaction . options . getNumber ( name )
211+ case ApplicationCommandOptionType . Mentionable :
212+ return interaction . options . getMentionable ( name )
213+ case ApplicationCommandOptionType . Attachment :
214+ return interaction . options . getAttachment ( name )
260215 default :
261216 return null
262217 }
0 commit comments