From 1b7400ae0a8752082bf3e6d93b9f255ac5c2c12a Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Mon, 2 Aug 2021 18:39:46 +0200 Subject: [PATCH] export MessageEmbed + redesigned error message --- index.ts | 7 ++-- src/Bot.ts | 96 ++++++++++++++++++++++---------------------- src/SystemMessage.ts | 2 +- 3 files changed, 52 insertions(+), 53 deletions(-) diff --git a/index.ts b/index.ts index 97ffb45..c37f831 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,6 @@ -import { Bot } from './src/Bot.js'; -import { Command } from './src/Command.js'; +import { Bot } from "./src/Bot.js"; +import { Command } from "./src/Command.js"; +import { MessageEmbed } from "discord.js"; export default Bot; -export { Bot, Command }; \ No newline at end of file +export { Bot, Command, MessageEmbed }; diff --git a/src/Bot.ts b/src/Bot.ts index fe29627..93798bc 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -106,59 +106,57 @@ export class Bot extends EventEmitter { } console.log("✔"); process.stdout.write("Connecting to Discord... "); - if (await this.client.login(this.token)) { - this.client.on("ready", () => { - console.log("✔\n"); - this.emit("READY"); - }); - this.client.on("message", async (m) => { - const cmdMsg: CommandMessageStructure | null = - this.commands.fetch(m); - if (cmdMsg?.command) { - this.emit("COMMAND", m, cmdMsg); - try { - await cmdMsg.command.start(m, cmdMsg.arguments); - } catch (e) { - if (e instanceof PermissionsError) { - this.messages.system.send( - "PERMISSION", - { - user: m.member || undefined, - command: cmdMsg.command, - }, - m.channel - ); - } else { - this.messages.system.send( - "ERROR", - { - command: cmdMsg.command, - user: m.member || undefined, - error: e, - }, - m.channel - ); - console.error(e); - } - this.emit("ERROR", e); - return; + await this.client.login(this.token); + this.client.on("ready", () => { + console.log("✔\n"); + this.emit("READY"); + }); + this.client.on("message", async (m) => { + const cmdMsg: CommandMessageStructure | null = + this.commands.fetch(m); + if (cmdMsg?.command) { + this.emit("COMMAND", m, cmdMsg); + try { + await cmdMsg.command.start(m, cmdMsg.arguments); + } catch (e) { + if (e instanceof PermissionsError) { + this.messages.system.send( + "PERMISSION", + { + user: m.member || undefined, + command: cmdMsg.command, + }, + m.channel + ); + } else { + this.messages.system.send( + "ERROR", + { + command: cmdMsg.command, + user: m.member || undefined, + error: e, + }, + m.channel + ); + console.error(e); } - } else if (cmdMsg) { - this.messages.system.send( - "NOT_FOUND", - { phrase: m.content, user: m.member || undefined }, - m.channel - ); - } else { - this.emit("MESSAGE", m); + this.emit("ERROR", e); + return; } - }); - } else { - return false; - } + } else if (cmdMsg) { + this.messages.system.send( + "NOT_FOUND", + { phrase: m.content, user: m.member || undefined }, + m.channel + ); + } else { + this.emit("MESSAGE", m); + } + }); return true; } catch (e) { - console.error(`ERROR! ${e.toString()}`); + console.log("❌"); + console.error(`[❌ ERROR] ${e.toString()}`); return false; } } diff --git a/src/SystemMessage.ts b/src/SystemMessage.ts index 781ff62..ad80db6 100644 --- a/src/SystemMessage.ts +++ b/src/SystemMessage.ts @@ -164,7 +164,7 @@ export class SystemMessageManager { return embed; } } else { - console.error("ERROR! System message: Incorrect parameter"); + console.error("[❌ ERROR] System message: Incorrect parameter"); return; } }