Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item can be undefined in Chapter 2.3 #74

Open
shinebayar-g opened this issue Feb 19, 2018 · 4 comments
Open

Item can be undefined in Chapter 2.3 #74

shinebayar-g opened this issue Feb 19, 2018 · 4 comments

Comments

@shinebayar-g
Copy link

shinebayar-g commented Feb 19, 2018

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)
@DentFuse
Copy link
Contributor

DentFuse commented Mar 4, 2018

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.

@urumo
Copy link

urumo commented Mar 22, 2018

same problem here, decided to copy the codi from the repo, got the same error

@andrewda
Copy link
Owner

https://dev.doctormckay.com/topic/885-typeerror-cannot-read-property-appid-of-undefined/

We should check to ensure the inventory isn't empty first.

@andrewda andrewda changed the title Chapter 2.3 error, not working. Item can be undefined in Chapter 2.3 Mar 23, 2018
@TheDefective
Copy link

Sorry to revive a dead thread but I had this same issue but removed the -1 from the inventory length and it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants