vylbot-app/src/client/events.ts
Vylpes 18e3f3d800
110 commandshelp about command errors which causes command to not run (#126)
* Change onMessage to onMessageCreate

* Fix help command
2022-04-15 16:12:46 +01:00

37 lines
1.1 KiB
TypeScript

import { Message } from "discord.js";
import ICommandItem from "../contracts/ICommandItem";
import SettingsHelper from "../helpers/SettingsHelper";
import { Util } from "./util";
export class Events {
private _util: Util;
constructor() {
this._util = new Util();
}
// Emit when a message is sent
// Used to check for commands
public async onMessageCreate(message: Message, commands: ICommandItem[]) {
if (!message.guild) return;
if (message.author.bot) return;
const prefix = await SettingsHelper.GetSetting("bot.prefix", message.guild.id);
if (!prefix) return;
if (message.content.substring(0, prefix.length).toLowerCase() == prefix.toLowerCase()) {
const args = message.content.substring(prefix.length).split(" ");
const name = args.shift();
if (!name) return;
await this._util.loadCommand(name, args, message, commands);
}
}
// Emit when bot is logged in and ready to use
public onReady() {
console.log("Ready");
}
}