Creating Events

To create an event, you have to pass in the following parameters:

  • Bot

  • HKandler

  • Whatever parameters are needed for the event

Ready Event

ready.js
module.exports = (bot, hkandler) => {
  console.log(`Logged in as ${bot.user.tag} and my prefix is ${hkandler.prefix}`);
};

Message Event

message.js
const { filter, errorEmbed } = require("hkutilities");
module.exports = (bot, hkandler, message) => {
  const { prefix } = hkandler;
  /*
  let's use the  filter to check if message is from a bot or the message is in dm's
  filter takes 1 paramter; message
  */
  if (filter(message) return;
  if (!message.content.startsWith(prefix)) return;
  const args = message.content.slice(prefix.length).trim().split(/ +/);
  const commandName = args.shift().toLowerCase();

  const command =
    hkandler.commands.get(commandName) ||
    hkandler.commands.find(
      (cmd) => cmd.aliases && cmd.aliases.includes(commandName)
    );
  if (!command) return;

  try {
    command.execute(bot, message, args, hkandler);
  } catch (error) {
    /*
    let's use the error embed function
    errorEmbed takes in 2 parameters; the channel, and the "error"
    */
    errorEmbed(message.channel, error);
  }
};

Last updated