Slash Commands

Slash Commands Setup

  1. Import Required Functions In your index.js file (or wherever you initialize your bot), start by importing the necessary functions:

    const { startBot, loadSlashs } = require('mvk-project');
  2. Create and Configure Your Bot Client Use the startBot function to create and configure your bot client:

    const client = startBot({
      token: '...', // Replace with your bot's token
      intents: [
        'Guilds',
        'GuildMessages',
        'MessageContent'
        // Add more intents if needed
      ],
      prefix: '!', // Prefix for your bot commands
      consoleLog: 'Bot ${bot.username} is online' // Optional message when the bot starts
    });
  3. Load Slash Commands To load and manage slash commands, use the loadSlashs function:

    loadSlashs('./slash_commands', client); // Loads slash commands from the specified folder
  4. Start Your Bot Finally, start your bot by running your index.js file using Node.js:

    node index.js

Example Slash Command: ping

The following functions will be explained in more detail later on. For now, you can use the example code below to see how it works:

const { getClient, newSlashCommand, sendMessage } = require('mvk-project');
const client = getClient();

module.exports = newSlashCommand({
    name: 'ping',
    description: 'Responds with Pong! and shows the bot\'s latency.',
    code: async function (interaction) {
        const ping = interaction.client.ws.ping;
        await interaction.reply(`Pong! The bot's latency is ${ping}ms.`);
    }
});


This setup will prepare your bot to handle slash commands and ensure everything is ready to function. You can add more functionality or commands by following similar steps to load events and prefix commands.

Last updated