export MessageEmbed + redesigned error message

This commit is contained in:
mmacierzanka committed 2021-08-02 18:39:46 +02:00
1 parent 217cc09b39
commit 1b7400ae0a
3 files changed
+52 -53

No files matched your search

+4 -3
View File
@@ -1,5 +1,6 @@
import { Bot } from './src/Bot.js'; import { Bot } from "./src/Bot.js";
import { Command } from './src/Command.js'; import { Command } from "./src/Command.js";
import { MessageEmbed } from "discord.js";
export default Bot; export default Bot;
export { Bot, Command }; export { Bot, Command, MessageEmbed };
+47 -49
View File
@@ -106,59 +106,57 @@ export class Bot extends EventEmitter {
} }
console.log("✔"); console.log("✔");
process.stdout.write("Connecting to Discord... "); process.stdout.write("Connecting to Discord... ");
if (await this.client.login(this.token)) { await this.client.login(this.token);
this.client.on("ready", () => { this.client.on("ready", () => {
console.log("✔\n"); console.log("✔\n");
this.emit("READY"); this.emit("READY");
}); });
this.client.on("message", async (m) => { this.client.on("message", async (m) => {
const cmdMsg: CommandMessageStructure | null = const cmdMsg: CommandMessageStructure | null =
this.commands.fetch(m); this.commands.fetch(m);
if (cmdMsg?.command) { if (cmdMsg?.command) {
this.emit("COMMAND", m, cmdMsg); this.emit("COMMAND", m, cmdMsg);
try { try {
await cmdMsg.command.start(m, cmdMsg.arguments); await cmdMsg.command.start(m, cmdMsg.arguments);
} catch (e) { } catch (e) {
if (e instanceof PermissionsError) { if (e instanceof PermissionsError) {
this.messages.system.send( this.messages.system.send(
"PERMISSION", "PERMISSION",
{ {
user: m.member || undefined, user: m.member || undefined,
command: cmdMsg.command, command: cmdMsg.command,
}, },
m.channel m.channel
); );
} else { } else {
this.messages.system.send( this.messages.system.send(
"ERROR", "ERROR",
{ {
command: cmdMsg.command, command: cmdMsg.command,
user: m.member || undefined, user: m.member || undefined,
error: e, error: e,
}, },
m.channel m.channel
); );
console.error(e); console.error(e);
}
this.emit("ERROR", e);
return;
} }
} else if (cmdMsg) { this.emit("ERROR", e);
this.messages.system.send( return;
"NOT_FOUND",
{ phrase: m.content, user: m.member || undefined },
m.channel
);
} else {
this.emit("MESSAGE", m);
} }
}); } else if (cmdMsg) {
} else { this.messages.system.send(
return false; "NOT_FOUND",
} { phrase: m.content, user: m.member || undefined },
m.channel
);
} else {
this.emit("MESSAGE", m);
}
});
return true; return true;
} catch (e) { } catch (e) {
console.error(`ERROR! ${e.toString()}`); console.log("❌");
console.error(`[❌ ERROR] ${e.toString()}`);
return false; return false;
} }
} }
+1 -1
View File
@@ -164,7 +164,7 @@ export class SystemMessageManager {
return embed; return embed;
} }
} else { } else {
console.error("ERROR! System message: Incorrect parameter"); console.error("[❌ ERROR] System message: Incorrect parameter");
return; return;
} }
} }