Skip to content

5) Adding Slash Commands

Oğuzhan edited this page Jul 21, 2022 · 8 revisions

First create a file that ends with .js extension and another same-named file that ends with .struct.js located in the directory you specified in the config.json's slashCommands.directory property.

Enter the file that ends with .struct.js and make a Slash Command.

Example:

new SlashCommandBuilder()
    .setDescription("example, " + guild.name)
    .setName("example");

You can click me and see the docs of Discord.SlashCommandBuilder

Now you can just add your in-file config and start coding!

In-file config properties

name

This should be defined in your in-file config.

This will be used while handling the command.

Example situation: If your command's structure name is myCommand and someone uses /myCommand command in a channel that your bot can see this command file will be triggered.

enabled

This is an optional property and false by default.

If you want your command to get triggered by using it adds this property.

dmAllowed

This is an optional property and false by default.

If you want your command to be able to run in DMs add this property.

botAllowed

This is an optional property and false by default.

If you want your command to be able to run by bots add this property.

Check Prefixed-slash commands page for prefixed-slash in-file configurations.

External variables

stop()

This stops your command and can have limitless arguments which won't matter.

interaction

This is a Discord.Interaction instance which caused your command.

channel

This is a Discord.Channel instance where the message was sent.

guild

This is a Discord.Guild instance or undefined if you enabled dmAllowed and used the command in a DM channel.

language

This is the language got from the guild of the interaction. Example: en_US

args

An object which represent the arguments of the slash command. Example: args.myTextArgument

subCommand

A string or undefined which is the used sub command used by the user.

subCommandGroup

A string or undefined which is the used sub command group used by the user.

structure

Discord.SlashCommandBuilder that you built in the .struct.js file.

command

This is a NodeJS.Global.SlashCommand instance which represents the current command. You can get in-file config properties using it: command.getConfigValue("name")