Setting up Slash Commands
You will need to follow properties to create a regular command and the following data, and interactionReply properties to create a slash command.
Here is a sample slash command created from our previous ping command:
const { SlashCommandBuilder } = require("discord.js");
module.exports = {
name: 'ping',
description: 'Ping Pong Command!',
aliases: ['p'],
guildOnly: true,
permissions: 0,
minArgs: 0,
usage: '',
data: new SlashCommandBuilder()
.setName("ping")
.setDescription("Ping Pong Command"),
execute(message, args, client) {
return message.channel.send('Pong.');
},
async interactionReply(interaction) {
await interaction.reply({
content: 'Pong!'
});
}
};
Properties
dataSlashCommandBuilder
This is where you define the properties of the slash command using the SlashCommandBuilder Class. You can follow the official Discord.js guide or builders guide, however, we are using interactionReply
and not using execute
for the slash command functionality.
interactionReply(interaction, client, level)
Promise<Interaction>
This is a function that is invoked when the command is called to be executed.
Property | Type | Required | Description |
---|---|---|---|
interaction | CommandInteraction Class | true | This is the command interaction object that represents a slash command interaction on Discord. |
client | Discord.Client | false | This is the Discord client object. |
level | Number | false | This is the user's permission level. |
returns Promise<Interaction>