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}`);
};
ready.ts
import { Client } from "discord.js"
import { HKandler } from "hkutilities/dist/structures/hkandler"
module.exports = (bot: Client, hkandler: 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);
}
};
message.ts
import { filter, errorEmbed } from "hkutilities";
import { HKandler } from "hkutilities/dist/structures/hkandler"
import { Client, Message } from "discord.js"
export = (bot: Client, hkandler: HKandler, message: 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