Honestly, don't comment if you have absolutely no clue what's going on.
This should work:
EDIT: You also have 3 other issues with your code that I did not notice at first (as I didn't look at the main code). 1.) You are using a deprecated method. You want to use https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/TradeOfferManager#getinventorycontentsappid-contextid-tradableonly-callback Example:
manager.getUserInventoryContents(partner, appid, contextid, true, (err, theirInv) => {...});
2.) Line 158 it needs to be either 'var', 'let' or 'const' unless you are wanting to re-define it.
3.) last issue (that I found) would be on line 163, what you want to do there is change it to
var keyToAdd = availableKey[0] //Change it simply to 'availableKey' if you want to add all of the keys found.
and from there refer to it as keyToAdd.
Back to your solution for 'checkAvailableKey' function
function checkAvailableKey(inventory, acceptedKeyList){
var availableKey = []; //Create an empty array where we can store item data.
for(var i=0; inventory.length>i;i++){ //Loop through inventory.
if (acceptedKeyList.indexOf(inventory[i].market_hash_name) >= 0){ //Check if there is this item in your array.
availableKey.push(inventory[i]); //Push all item info, such as assetid, name, amount etc.
}
}
return availableKey; //return the array with item data.
/*
P.S:
You don't need to make the function ask for the array every time, just add the array with accepted keys in your global scope.
However, this is prefered if you have multiple arrays which you want to check.
*/
}
just call
manager.getExchangeDetails();
https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/TradeOffer#getexchangedetailsgetdetailsiffailed-callback
offer.itemsToReceive.forEach(function(item) {
if (item.appid == "440" && item.market_hash_name == "Scrap Metal") {
console.log("It's a bird! It's a plane! IT'S A SCRAP METAL!");
}
}
);
Something I made you real quick. You can do it the same way for itemsToGive
You can also get some of this info out of it: https://github.com/DoctorMcKay/node-steamcommunity/wiki/CEconItem