Skip to content
T.F.A edited this page Sep 9, 2022 · 4 revisions

Welcome to the DiscordJS-V14-Bot-Template wiki!

Welcome to the wiki! Here, I'm going to show you how to create slash, user, message commands, slash command options, and more!

⚠️ If there is something wrong in this wiki, please tell me in my DMs on Discord (T.F.A#7524) so I can fix it and users won't make any mistakes.

Create a Slash command:

Registering a Slash command into Discord:

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:

2022-09-09 16_45_22-Window

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 name Ping or PING for an example, it won't work, change it into ping.

2022-09-09 16_51_30-Window

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:

2022-09-09 16_55_00-Window

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.

2022-09-09 16_57_08-Window

Command permissions:

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.

2022-09-09 17_09_04-Window

ℹ️ Info: If you want the command can be executed for everyone, remove that line of code or set the value into SendMessages.

Make the slash command respond:

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!

Reply with a normal message:

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:

2022-09-09 17_12_05-Window

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:

2022-09-09 17_06_13-Window

Reply with an Embed message:

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.

2022-09-09 17_20_04-Window

Result:

2022-09-09 17_20_51-Window

Replying with an ephemeral message:

This is a simple one, here is an example for the embed: (You can also use it for normal messages)

2022-09-09 17_23_28-Window

Result:

2022-09-09 17_24_31-Window

Slash commands options:

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

Getting an option's value:

const a = interaction.options.get('YOUR OPTION NAME').value;

Choices:

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).

Sub-commands:

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
			}
		]
	}
]

Getting a Sub command's value:

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;

Create a User command:

Registering User commands into Discord:

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:

2022-09-09 17_37_35-Window

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.

2022-09-09 17_40_13-Window

Make the user command respond:

It's the same thing as the Slash command!

Create a Message command:

Registering Message commands into Discord:

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:

2022-09-09 17_44_05-Window

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.

2022-09-09 17_45_39-Window

Make the user command respond:

It's the same thing as the Slash command!

Project Issues:

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.

Clone this wiki locally