Creating your first command

With this page, you will create and use your first command.

Creating a command with SlashDiscord.js is very easy!

// Basic imports

const { Client } = require('discord.js');
const { SlashCommandHandler } = require('slashdiscord.js');

// Creating the instances

const client = new Client();

// The command handler requires the client in order to run the commands.

const handler = new SlashCommandHandler({ client });

// Your HelloWorld command

handler.addCommand({
    name: 'Hello',
    description: 'My first command.'
})

// This callback will run when the a slashcommand gets executed.

.run(interaction => {
    interaction.reply('Hello World!');
})

// And lastly, login into the client using a bot token.

client.login('BOT_TOKEN');

Take a look at the example bot here (uses TypeScript.)

Next up, lets invite the bot

Last updated

Was this helpful?