Creating your first prefix command

Simple Prefix Command

A guide to creating a command for Discord wouldn't be a guide if it didn't have the ping command. See below how to create it using the Seface Kit!

commands/ping.js
const command = {
  name: 'ping',
  description: 'Ping! Pong!',
  execute: async (client, message, args, instance) => {
    message.channel.send('Pong!');
  }
};

module.exports = { command };

Remember, you must name the constant as command, otherwise the TypeError: Cannot read properties of undefined will be returned.

Advanced Prefix Command

Now let's see how we can create a advanced command.

commands/moderation/kick.js
const command = {
  name: 'kick',
  description: 'Kick members from the server.',
  execute: async (client, message, args, instance) => {
    const sender = message.guild.members.cache.get(message.author.id);
    const userToKick = message.mentions.members.first();

    if (!userToKick) {
      message.channel.send('You need to mention a user to kick!');
      return;
    }

    if (!sender.permissions.has('KICK_MEMBERS')) {
      message.channel.send('You don\'t have permission to use this command!');
      return;
    }

    if (!userToKick.kickable) {
      message.channel.send('You can\'t kick this user!');
      return;
    }

    userToKick.kick();
    message.reply('User kicked!');
  }
};

module.exports = { command };

Adding Aliases

To add aliases to Prefix Commands, just add the aliases property.

commands/ping.ts
import { PrefixCommand } from 'seface-kit';

export const command: PrefixCommand = {
  name: 'ping',
  description: 'Ping! Pong!',
  aliases: ['p'],
  execute: async (client, message, args) => {
    message.channel.send('Pong!');
  }
};
commands/ping.js
const command = {
  name: 'ping',
  description: 'Ping! Pong!',
  aliases: ['p'],
  execute: async (client, message, args) => {
    message.channel.send('Pong!');
  }
};

module.exports = { command };

Last updated