javascriptnode.jssteam-web-apisteambot

Need Help Declining Steam Offers That Take Things From Me


Ok so I have a code from a steam bot the accepts and declines trades if the offer state is correct. But I would like it to accept trade offers that give me things but decline trade offers that are made by someone else asking for things.

      if(body.response.trade_offers_received){
    body.response.trade_offers_received.forEach(function(offer) {

      if (offer.trade_offer_state == 2){
          offers.acceptOffer({tradeOfferId: offer.tradeofferid});
          }
        else {
          offers.declineOffer({tradeOfferId: offer.tradeofferid});
        }
      }
    );
  }

Solution

  • Not exactly sure what bot you're basing your code off, however after looking at the steam api for trade offers, there should be an array called "items_to_give" which you could check and see if it is empty before accepting.

    if (offer.trade_offer_state === 2 && (!offer.hasOwnProperty("items_to_give") || offer.items_to_give.length === 0)){
    

    So above we check if we do not have the "items_to_give" key, which doesn't exist if you are giving nothing. Then we check to make 100% sure that it has no items in it, just in case Steam decides to include empty keys with their API at a later date.

    After looking at the steam api again, I believe your code could be improved if you also checked for TradeOfferStateCountered(4), which would let you accept counter offers as well. Here is the code for that

    if ((offer.trade_offer_state === 2 || offer.trade_offer_state === 4) && (!offer.hasOwnProperty("items_to_give") || offer.items_to_give.length === 0)){