node-steam-guide
node-steam-guide copied to clipboard
Item can be `undefined` in Chapter 2.3
Hi first of all i must say thanks to author for this awesome guide. I was following chapters one by one and here I'm at chapter 2.3 everything was working as intended until this part:
I don't think it's mandatory, but just fyi :D
function sendRandomItem() {
const partner = 'partner_steam_id'; #Note: I used your_trusted_account_id here as mentioned in Chapter 2.2
const appid = 440; #Note: I tried both app id 440 (TF2) and 730 (CSGO), PS: My bot has CSGO purchased, Trusted account didn't buy CSGO. But trade with CSGO items were working.
const contextid = 2;
const offer = manager.createOffer(partner);
manager.loadInventory(appid, contextid, true, (err, myInv) => {
if (err) {
console.log(err);
} else {
const myItem = myInv[Math.floor(Math.random() * myInv.length - 1)];
offer.addMyItem(myItem);
manager.loadUserInventory(
partner,
appid,
contextid,
true,
(err, theirInv) => {
if (err) {
console.log(err);
} else {
const theirItem =
theirInv[Math.floor(Math.random() * theirInv.length - 1)];
offer.addTheirItem(theirItem);
offer.setMessage(
`Will you trade your ${theirItem.name} for my ${myItem.name}?`
);
offer.send((err, status) => {
if (err) {
console.log(err);
} else {
console.log(`Sent offer. Status: ${status}.`);
}
});
}
}
);
}
});
}
this part of code giving the following result:
Logged into Steam
c:\Node\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:254
if (typeof details.appid === 'undefined' || typeof details.contextid === 'undefined' || (typeof details.assetid === 'undefined' && typeof details.id === 'undefined')) {
^
TypeError: Cannot read property 'appid' of undefined
at addItem (c:\Node\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:254:21)
at TradeOffer.addMyItem (c:\Node\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:167:9)
at manager.loadInventory (c:\Node\project2.js:70:13)
at SteamCommunity.<anonymous> (c:\Node\node_modules\steamcommunity\components\users.js:342:5)
at Request._callback (c:\Node\node_modules\steamcommunity\components\http.js:67:15)
at Request.self.callback (c:\Node\node_modules\request\request.js:186:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (c:\Node\node_modules\request\request.js:1163:10)
at emitOne (events.js:116:13)
Are you sure you have provided the part of the code which errors? Cause I can't see any if conditions in ur provided code, also you haven't defined details
, that might be the problem.
same problem here, decided to copy the codi from the repo, got the same error
https://dev.doctormckay.com/topic/885-typeerror-cannot-read-property-appid-of-undefined/
We should check to ensure the inventory isn't empty first.
Sorry to revive a dead thread but I had this same issue but removed the -1 from the inventory length and it worked