Mr Game and Watch Posted January 21, 2018 Report Posted January 21, 2018 (edited) Hello!I'm trying to send automatic offers. I have two functions for doing this: One for the ones I want to send and other to send counter offers. The first one works perfect (Thanks again for helping me with that), then I decided to copy-paste that for the second and change it a little. But here's what is strange: the couner function can send offers, but can't confirm them because the offer id is always null. Here are the 2 offers objects: TradeOffer { partner: censored, id: '2192436500', message: 'Here's your trade', state: 9, itemsToGive: [ ... ], itemsToReceive: [ ... ], isOurOffer: true, created: 2018-01-21T11:03:44.021Z, updated: 2018-01-21T11:03:44.021Z, expires: 2018-02-04T11:03:44.021Z, tradeID: null, fromRealTimeTrade: false, confirmationMethod: 2, escrowEnds: null, rawJson: '' } And this is the wrong one: TradeOffer { partner: censored, id: null, message: 'That was not the correct price. Here's what I wanted.', state: 1, itemsToGive: [ ... ], itemsToReceive: [ ... ], isOurOffer: true, created: null, updated: null, expires: null, tradeID: null, fromRealTimeTrade: false, confirmationMethod: null, escrowEnds: null, rawJson: '' } Here is the working one: var offer = manager.createOffer(item.trade_route); offer.addMyItems(items_to_send); offer.addTheirItem({"appid": 440, "contextid": 2, "assetid": item.currentID}); offer.setMessage("Here's your trade"); offer.send(function(err, status) { if (err) { console.log(err); return; } console.log(offer); //here's the one I posted above if (status == 'pending') { console.log(`Offer #${offer.id} sent, but requires confirmation`); setTimeout( function(){ community.acceptConfirmationForObject(key, offer.id, function(err) { if (err) { console.log(err); } else { console.log("Offer " + offer.id +" confirmed"); } }); }, 2000 ); } else { console.log(`Offer #${offer.id} sent successfully`); } }); Here's the worng one (counter offer): var offer = manager.createOffer(trade_url); manager.loadUserInventory(user_id, 440, 2, false, function (err, inventory, currencies) { if ('code for validating other things') { offer.addMyItem(...); offer.addTheirItems(items_to_send); offer.setMessage("That was not the correct price. Here's what I wanted."); offer.send(function (err, status) { if (err) { console.log(err); } if (status == 'pending') { console.log(offer) // Here's the one I posted above setTimeout(function () { community.acceptConfirmationForObject(key, offer.id, function (err) { if (err) { console.log(err); } else { console.log("Offer " + offer.id + " confirmed"); } }); }, 4000); } else { console.log(`Offer #${offer.id} sent successfully`); } }); } else { console.log("Validation failed") ... non related code } }); }); Why the second one can't have the offer.id? Any kinf of help would be aprreciated Note: I had to remove the non-related code and coments... sorry if you test it and fails. Edited January 21, 2018 by Mr Game and Watch Quote
Vanilla Posted January 21, 2018 Report Posted January 21, 2018 (edited) From what I know, you need to create new variable with offer.counter(); It will return the old trades (that we want to counter), do something with it, and send the counter offer this might helps. Edited January 21, 2018 by Vanilla Quote
Mr Game and Watch Posted January 21, 2018 Author Report Posted January 21, 2018 I'll try that.But I'm kinda worried. I mean: Now I can avoid this null problem with counter, but... what wold happen if I need more functions to send objects? That would be a problem. Thanks Vanilla. I'l try that. Has this error happened to you before? I mean, get null info of your offers. Quote
Dr. McKay Posted January 21, 2018 Report Posted January 21, 2018 Your second example doesn't have a return after you check err. Is there just an error message above it that you're missing? Quote
Mr Game and Watch Posted January 22, 2018 Author Report Posted January 22, 2018 Ups, sorry about that. I deleted that line, but in my code there's a return there (I guess I deleted that line by mistake). This is what happens in the second function (the "non-working" one): It loads the offer (with a null id in that moment), loads the items and set the message. Then, it sends correctly the offer. It checks if the status is "pending" (it is). But it goes to error, saying that it can't confirm an offer with null id. I'm working with the solution Vanilla told, but... I wanted to know why that happened. It's just curious. Thanks Dr. McKay Quote
Vanilla Posted January 24, 2018 Report Posted January 24, 2018 Has this error happened to you before? I mean, get null info of your offers. Nope, never happened to me.If incoming trade offer didn't match with my "rules", my bot successfully counter the trade.The code above is pretty much how I counter the incoming trade offer. Oh by the way, I'm using newOffer event to get incomming trade offer. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.