-
Notifications
You must be signed in to change notification settings - Fork 160
Home
Welcome to the wiki! Here, I'm going to show you how to create slash, user, message commands, slash command options, and more!
To create a slash command, create a file in the slash folder and name it anything you want, and also ends with .js
(Which is the file extension). Go to the folder templates
, go to the file slash_command.js
, copy the code there and paste it into the new file that you have created. For now, I have created a file called command.js
, here's a picture below:
Let's create a slash command and register it on Discord!
Now, we are going to fill the variable name
's value into a slash command name, I chose command
. Also you need to provide the slash command's description! I chose Just a test
.
⚠️ Warning: Slash commands names always must be in lower case, so if you have provided your slash command namePing
orPING
for an example, it won't work, change it intoping
.
Use now the shortcut CTRL + S
(If you are in Windows) to save the file. Now, type in the terminal node .
or node index.js
to start running your bot, and you should see that your command has been loaded. Here is what I got:
Now open Discord, go to any server that your is in, and check the slash commands on your bot. The command that you have created should be added.
Do you want your server members to not use this command, and only your server moderators (for an example)? Yep, there is a way to do it!
Go to your command file, use the DEFAULT_MEMBER_PERMISSIONS
for the permissions. If you want your slash command works for the members that are having the permission Ban Members
, type then BanMembers
.
ℹ️ Info: If you want the command can be executed for everyone, remove that line of code or set the value into
SendMessages
.
Now, if you execute the command, it should respond with This interaction failed
because we didn't provide something for the slash command to execute! let's make the command reply when we execute it!
Go to your command file, in the module, we see the run
variable, this will make the command response. For now, we are going to make the bot reply with a normal message, here is a simple one:
Now, click on the terminal tab, use the shortcut CTRL + C
to stop the terminal from working, and then type node .
or node index.js
to start your bot. Now, if we execute the command, it should respond with Hi there!
. Here is what I got:
To make an embedded message, import the builder EmbedBuilder
from discord.js package. (Already added to all commands templates)
const { EmbedBuilder } = require('discord.js');
Let's create a simple embed message!
Discord.js Embed messages guide is located here.
Result:
This is a simple one, here is an example for the embed: (You can also use it for normal messages)
Result:
Discord.js slash commands options guide is located here.
Creating options should be an Array, here's an example:
options: [
{
name: "text",
description: "write anything you want!",
type: 3,
required: false
}
]
⚠️ WARNING: The name of any option always must be in lower case, like the slash command name.
⚠️ WARNING: All the required options (required = true
) should be the first options, and then the not required options.
We used the type 3
for the String option. There are other option types:
Name: | Value: |
---|---|
STRING | 3 |
INTEGER | 4 |
BOOLEAN | 5 |
USER | 6 |
CHANNEL | 7 |
ROLE | 8 |
MENTIONABLE | 9 |
NUMBER | 10 |
ATTACHMENT | 11 |
const a = interaction.options.get('YOUR OPTION NAME').value;
options: [
{
name: "choice",
description: "Choose something!",
type: 3,
required: true,
choices: [
{
name: "Choice #1",
value: "1"
},
{
name: "Choice #2",
value: "2"
}
]
}
]
⚠️ WARNING: Choices should be in the option type string (3).
Discord.js Sub-commands guide are located here.
Sub-commands type is always 1
. You can add more options in an option if you are using the sub-command type.
options: [
{
name: "sub",
description: "A sub command",
type: 1,
options: [
{
name: "text",
description: "Write anything you want!",
type: 3,
required: true
}
]
},
{
name: "sub-2",
description: "Sub command 2",
type: 1,
options: [
{
name: "text",
description: "Write anything you want!",
type: 3,
required: true
}
]
}
]
const sub = interaction.options.getSubcommand();
if (sub === "sub") {
// Your code for sub-command #1.
} else if (sub === "sub-2") {
// Your code for sub-command #2.
} else return;
To create a user command, create a file in the user folder and name it anything you want, and also ends with .js
(Which is the file extension). Go to the folder templates
, go to the file user_command.js
, copy the code there and paste it into the new file that you have created. For now, I have created a file called user.js
, here's a picture below:
Let's create a user command and register it on Discord!
Now, we are going to fill the variable name
's value into a user command name, I chose user
. The type is always 2
, do not change it!
ℹ️ Note: User commands names can contain capital letters.
It's the same thing as the Slash command!
To create a message command, create a file in the message folder and name it anything you want, and also ends with .js
(Which is the file extension). Go to the folder templates
, go to the file message_command.js
, copy the code there and paste it into the new file that you have created. For now, I have created a file called message.js
, here's a picture below:
Let's create a user command and register it on Discord!
Now, we are going to fill the variable name
's value into a user command name, I chose message
. The type is always 3
, do not change it!
ℹ️ Note: Message commands names can contain capital letters, like User commands.
It's the same thing as the Slash command!
Is there something that doesn't work? Create an issue here and I will respond as fast as possible!
If you have some ideas, you can create a Pull request here.