seishun / node-steam

Interface directly with Steam servers from Node.js
MIT License
1k stars 180 forks source link

TypeError: Cannot read property 'on' of undefined at new SteamRichPresence #371

Closed mindcrimes closed 8 years ago

mindcrimes commented 8 years ago

TypeError: Cannot read property 'on' of undefined at new SteamRichPresence (/home/carl/node-steam/node_modules/steam/lib/handlers/rich_presence/index.js:12:15) at Object. (/home/carl/node-steam/example.js:8:15) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10) at startup (node.js:129:16) at node.js:814:3

code i used: var fs = require('fs'); var Steam = require('steam'); var SteamGroups = require('steam-groups');

// Create new SteamClient object and pass it as a constructor param var client = new Steam.SteamClient(); var steamFriends = new Steam.SteamFriends(client); var steamRP = new Steam.SteamRichPresence(steamClient, 570); // if we've saved a server list, use it if (fs.existsSync('servers')) { Steam.servers = JSON.parse(fs.readFileSync('servers')); }

var steamClient = new Steam.SteamClient(); var steamUser = new Steam.SteamUser(steamClient); var steamFriends = new Steam.SteamFriends(steamClient);

var steamGroups = new SteamGroups(client, steamClient);

steamClient.connect(); steamClient.on('connected', function() { steamUser.logOn({ account_name: 'username', password: 'password', two_factor_code: 'code' }); });

steamClient.on('logOnResponse', function(logonResp) { if (logonResp.eresult == Steam.EResult.OK) { console.log('Logged in!'); steamFriends.setPersonaState(Steam.EPersonaState.Snooze); // to display your bot's status as "Online" steamFriends.setPersonaName('Carl'); // to change its nickname steamRP.request(['76561198130617496', '76561198049861518']); steamRP.upload( { RP: { status: "Competitive Inferno [ 3 : 10 ]", version: "13503", time: "4411.216601", "game:mode": "competitive", "game:mapgroupname": "mg_de_inferno", "game:map": "random", "game:server": "kv", "watch": "1", "game:score": "[ 3 : 1]" } }) } });

steamClient.on('servers', function(servers) { fs.writeFile('servers', JSON.stringify(servers)); }); steamFriends.on('friend', function(source, type) { //auto accept friend requests if(type == Steam.EFriendRelationship.RequestRecipient) { console.log("Accepted a friend request from: " + source); steamFriends.addFriend(source); } }); steamFriends.on('chatInvite', function(chatRoomID, chatRoomName, patronID) { console.log('Got an invite to ' + chatRoomName + ' from ' + steamFriends.personaStates[patronID].player_name); steamFriends.joinChat(chatRoomID); // autojoin on invite }); steamFriends.on('relationships', function() { for (var prop in steamFriends.friends) { if (steamFriends.friends.hasOwnProperty(prop)) { if (steamFriends.friends[prop] == 2) { steamFriends.addFriend(prop); console.log("Accepted a friend request from (offline): " + prop); } } } }); steamFriends.on('message', function(source, message, type, chatter) { // respond to both chat room and private messages var res = message.split(" ") if (message == '!help') { steamFriends.sendMessage(source, 'h', Steam.EChatEntryType.ChatMsg); }else { console.log('Received message: ' + res);
}

});

steamFriends.on('chatStateChange', function(stateChange, chatterActedOn, steamIdChat, chatterActedBy) { if (stateChange == Steam.EChatMemberStateChange.Kicked && chatterActedOn == steamClient.steamID) { steamFriends.joinChat(steamIdChat); // autorejoin! } });

steamFriends.on('clanState', function(clanState) { if (clanState.announcements.length) { console.log('Group with SteamID ' + clanState.steamid_clan + ' has posted ' + clanState.announcements[0].headline); } });

seishun commented 8 years ago

You're passing undefined to SteamRichPresence constructor.

mindcrimes commented 8 years ago

how do i prevent it from being passed?

scholtzm commented 8 years ago
var client = new Steam.SteamClient();
var steamFriends = new Steam.SteamFriends(client); // OK
var steamRP = new Steam.SteamRichPresence(steamClient, 570); // steamClient does not exist
mindcrimes commented 8 years ago

replaced that steamRP line with var steamRP = new Steam.SteamRichPresence(client, 570); and i still get the same error

seishun commented 8 years ago

This is not a JavaScript helpdesk.