nori nori - 1 year ago 360
Javascript Question

Node.js Steam Chat Bot

I want to make a Steam Bot using Node, and I have succesfully set it up and works swell.

Thing is, if I want to log commands, only one (so far) works, that's the /test command.

My code for checking the message(s) a.k.a commands:

steamBot.on('message', function(source, message, type, chatter) {

console.log('Received message: ' + message);
if (message == '/test') {

steamBot.sendMessage(source, 'It works!', Steam.EChatEntryType.ChatMsg);
} else {
steamBot.sendMessage(source, 'Use /help.', Steam.EchatEntryType.ChatMsg);

So, if I send the /test command to the bot using another account, it works, displaying "It works!", but if I send any other message, it doesn't display "Use /help". It shuts down the application, followed by these errors:

TypeError: Cannot read property 'ChatMsg' of undefined
at SteamClient.<anonymous> (/home/juniper/Downloads/Please/please3.js:32:105)
at emitThree (events.js:97:13)
at SteamClient.emit (events.js:175:7)
at SteamClient.handlers.(anonymous function) (/home/juniper/node_modules/steam/lib/handlers/friends.js:250:8)
at SteamClient._netMsgReceived (/home/juniper/node_modules/steam/lib/steam_client.js:106:26)
at SteamClient.handlers.(anonymous function) (/home/juniper/node_modules/steam/lib/steam_client.js:192:10)
at SteamClient._netMsgReceived (/home/juniper/node_modules/steam/lib/steam_client.js:106:26)
at emitOne (events.js:77:13)
at Connection.emit (events.js:169:7)
at Connection._readPacket (/home/juniper/node_modules/steam/lib/connection.js:50:8)


Answer Source

You have a typo: EChatEntryType in the first sendMessage, EchatEntryType in the second. Notice the lowercase c. Which one is it?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download