tmijs / tmi.js

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

message.startsWith is not a function #348

Closed whitesockies closed 5 years ago

whitesockies commented 5 years ago

Source

client.on('chat', (uptime, channel, user, message, self) => {
if(message.startsWith("!")){
  let args = message.split(' ')

  let command = args[0].split('!')[1].toLowerCase();

  try {

    let command_file = require('./commands/' + command + '.js')
    command_file.run(client, message, args, channel, uptime);
  }
  catch(error) {

    console.log("no " + command + " command")
  }
}
})

Actual behaviour: No response from the bot.

Expected behaviour: The bot will look for instances of a "command" and will do the action of whatever "command".js is.

Error log:

TypeError: message.startsWith is not a function
at client.on (/app/index.js:70:12)
    at client.EventEmitter.emit (/app/node_modules/tmi.js/lib/events.js:101:25)
    at client.EventEmitter.emits (/app/node_modules/tmi.js/lib/events.js:64:19)
    at client.handleMessage (/app/node_modules/tmi.js/lib/client.js:1003:34)
    at parts.forEach (/app/node_modules/tmi.js/lib/client.js:1080:36)
    at Array.forEach (<anonymous>)
    at client._onMessage (/app/node_modules/tmi.js/lib/client.js:1079:11)
    at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:120:16)
    at WebSocket.emit (events.js:189:13)
    at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:742:20)

Server configuration

AlcaDesign commented 5 years ago

You should try debugging your arguments. If you tried to log all of them you'd probably realize that "uptime" is not part of the event.

(uptime, channel, user, message, self) => {

Should be

(channel, user, message, self) => {