tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.54k stars 217 forks source link

Error: Cannot get the Args #420

Closed FReichelt closed 3 years ago

FReichelt commented 3 years ago

Actual behaviour: Crashes with an error of tmi.js

Expected behaviour: Should just get the args.

Error log:

Hi, TepixxBot is now online!
[12:11] info: [#unknownfllooo] <unknownfllooo>: !clear
Debugger listening on ws://127.0.0.1:53432/f49ed34d-2a54-45fb-979d-5b5842eb37d7
FC:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\commands.js:361
        if ((message.startsWith(".") && !message.startsWith("..")) || message.startsWith("/") || message.startsWith("\\")) {
                     ^

TypeError: Cannot read property 'startsWith' of undefined
    at client.say (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\commands.js:361:22)
    at client.<anonymous> (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\index.js:93:13)    
    at client.EventEmitter.emit (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\events.js:101:25)
    at client.EventEmitter.emits (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\events.js:64:19)
    at client.handleMessage (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\client.js:1003:34)
    at C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\client.js:1080:36
    at Array.forEach (<anonymous>)
    at client._onMessage (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\client.js:1079:11)
    at WebSocket.onMessage (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:314:20)
or help, see: https://no

Code

Bot.on("chat", (channel, user, message, self)  => {

  var TwitchArgs = message.split(' ')[1]

  var isBroadcaster = channel.replace('#', '') == user.username;

  var owner = "unknownfllooo" 

  const args = message.split(" ")[1];

  if (self) return;
  Bot.isMod(Bot.channel, Bot.getUsername()); {
        Bot.say(user["username"])
      if(message.startsWith( TwitchPrefix + "test")) {
        Bot.say(channel, "Das war ein Test!!")
        Bot.say(channel, TwitchArgs[1])
      }

    if(message.startsWith(TwitchPrefix + "clear")) {
        if (user.mod || isBroadcaster || user["username"] == owner) {
          Bot.clear(channel);
        } else Bot.say(channel, "Du hast keine Rechte für diesen Command")
      }

    }
});

Server configuration

FReichelt commented 3 years ago

The error isn't from the args it's from the Bot.say(user["username"]);

Hi, TepixxBot is now online!
[12:21] info: [#unknownfllooo] <unknownfllooo>: s
1
2
3
4
5
Waiting for the debugger to disconnect...
Debugger listening on ws://127.0.0.1:53689/3bb9745e-d87d-43ea-a6d7-116dae305c1C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\commands.js:361
        if ((message.startsWith(".") && !message.startsWith("..")) || message.startsWith("/") || message.startsWith("\\")) {
                     ^

TypeError: Cannot read property 'startsWith' of undefined
    at client.say (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\commands.js:361:22)
    at client.<anonymous> (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\index.js:92:13)    
    at client.EventEmitter.emit (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\events.js:101:25)
    at client.EventEmitter.emits (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\events.js:64:19)
    at client.handleMessage (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\client.js:1003:34)
    at C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\client.js:1080:36
    at Array.forEach (<anonymous>)
    at client._onMessage (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\lib\client.js:1079:11)
    at WebSocket.onMessage (C:\Users\FVKR\OneDrive\Desktop\Tepixx Bot\node_modules\tmi.js\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:314:20)
3
FReichelt commented 3 years ago

So now i fixed it so i will close this error

AlcaDesign commented 3 years ago

The say method requires a channel and then message.

client.on('message', (channel, tags, message, self) => {
    if(self) return;
    client.say(channel, `@${tags.username} Hello`);
});