From 8f5939983bb9de7f56024135757b38769b1e412b Mon Sep 17 00:00:00 2001 From: Joonas Date: Sat, 11 Feb 2023 14:10:13 +0200 Subject: [PATCH] check if command in command object and add more logging --- clients/twitch.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/clients/twitch.js b/clients/twitch.js index 36a5676..1c44592 100644 --- a/clients/twitch.js +++ b/clients/twitch.js @@ -16,13 +16,12 @@ let client = new ChatClient({ client.use(new SlowModeRateLimiter(client)); client.use(new AlternateMessageModifier(client)); client.commands = getCommands(); +console.log("Commands loaded"); client.on("ready", async () => { console.log("connected to chat"); client.joinAll([process.env.TWITCH_USERNAME, "rollinjuusto", "catsh"]); - await client - .say(process.env.TWITCH_USERNAME, "MrDestructoid") - .catch((err) => console.log(err)); + console.log("Joined channels"); }); client.on("close", async (error) => { @@ -43,6 +42,11 @@ client.on("PRIVMSG", async (msg) => { if (splitted[0] === process.env.BOT_PREFIX) { try { + if (!client.commands.hasOwnProperty(splitted[1])) { + await client.say(msg.channelName, `${msg.displayName}, not a command`); + return; + } + if (client.commands[splitted[1]].restricted) { if (!msg.badges.hasBroadcaster) { if (!msg.isMod) { @@ -74,12 +78,7 @@ client.on("PRIVMSG", async (msg) => { await client.commands[splitted[1]].run(client, msg, splitted); } catch (err) { - await client - .say( - msg.channelName, - `${msg.displayName}, not a command or something went wrong` - ) - .catch((err) => console.log(err)); + console.error("Something very unexpected happened: " + err.message); } } });