Slash Commands have some unique features unlike messageCommand
and userCommand
.
Options
Slash commands can take options
. These could be variables like strings
, numbers
, or even channels
. JellyCommands
uses discord.js
’s system to provide a nice API on top.
See all available options.
Providing Options
You can provide options with the options property.
import { command } from ' jellycommands ' ;
description: ' A short description of what the command does ' ,
description: ' Channel to send a message into ' ,
run : ( { interaction } ) => {
// We set the second argument to true as this option is marked as required
const channel = interaction . options . getChannel ( ' channel ' , true );
// We can then use this channel!
console . log ( channel . name );
Unlike the discord.js
built in options, you can provide the option type as a string
. If you prefer, however, you can provide it as an enum
.
import { ApplicationCommandOptionType } from ' discord.js ' ;
import { command } from ' jellycommands ' ;
type: ApplicationCommandOptionType . Channel ,
description: ' Channel to send a message into ' ,
Autocomplete
Some Slash Command Options support the autocomplete
property. When set to true
, you can use the autocomplete
handler.
For example, let’s write a command that returns a color and provides autocomplete on the color names:
import { command } from ' jellycommands ' ;
const colors = [ ' Violet ' , ' Indigo ' , ' Blue ' , ' Green ' , ' Yellow ' , ' Orange ' , ' Red ' ];
description: ' send a rainbow ' ,
description: ' The color of the thing idk ' ,
run : ( { interaction } ) => {
interaction . reply ( interaction . options . getString ( ' color ' , true ));
autocomplete : async ( { interaction } ) => {
// Get the name of the option that is being autocompleted
const focused = interaction . options . getFocused ( true );
if ( focused . name === ' color ' ) {
// Respond with 3 colours that match the current string
. filter ( ( color ) => color . startsWith ( focused . value ))
. map ( ( color ) => ({ name: color , value: color }))