Packages@robojs/discordjs
createCommandConfig()
Function: createCommandConfig()
function createCommandConfig<C>(config): CCreates a command configuration with proper type inference. This is a type-safe identity function that helps TypeScript infer option types.
Type Parameters
| Type Parameter |
|---|
C extends CommandConfig |
Parameters
| Parameter | Type | Description |
|---|---|---|
config | SmartCommandConfig<C> | The command configuration object |
Returns
C
The same configuration with inferred types
Examples
import { createCommandConfig } from '@robojs/discordjs'
export const config = createCommandConfig({
description: 'Greet someone',
options: [
{ name: 'user', type: 'user', required: true },
{ name: 'message', type: 'string' }
]
})
// TypeScript knows: options.user is User, options.message is string | undefined
export default (interaction, options) => {
return `Hello ${options.user.username}! ${options.message ?? 'Welcome!'}`
}// With choices - TypeScript infers literal types
export const config = createCommandConfig({
description: 'Pick a color',
options: [
{
name: 'color',
type: 'string',
required: true,
choices: [
{ name: 'Red', value: 'red' },
{ name: 'Blue', value: 'blue' }
]
}
]
})
// TypeScript knows: options.color is 'red' | 'blue'
export default (interaction, options) => {
if (options.color === 'red') {
return 'You picked red!'
}
return 'You picked blue!'
}