TextDynasty Posted February 6, 2019 Report Posted February 6, 2019 C:\Users\lokin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:255 throw new Error("Missing appid, contextid, or assetid parameter"); ^ Error: Missing appid, contextid, or assetid parameter at addItem (C:\Users\lokin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:255:9) at TradeOffer.addMyItem (C:\Users\lokin\node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:167:9) at C:\Users\lokin\OneDrive\New folder\bot.js:48:23 at SteamCommunity.<anonymous> (C:\Users\lokin\node_modules\steamcommunity\components\users.js:384:5) at Request._callback (C:\Users\lokin\node_modules\steamcommunity\components\http.js:67:15) at Request.self.callback (C:\Users\lokin\node_modules\request\request.js:185:22) at Request.emit (events.js:182:13) at Request.<anonymous> (C:\Users\lokin\node_modules\request\request.js:1161:10) at Request.emit (events.js:182:13) at Gunzip.<anonymous> (C:\Users\lokin\node_modules\request\request.js:1083:12) Error ^^ I found some examples of creating trade offers on steam but I don't quite understand how to do it. I would like to first differentiate the refined metal from the TF2 inventory and send a certain number (eg 5 refined metal) to the owner when it has more than 5 in its backpack. const SteamUser = require('steam-user'); const SteamCommunity = require('steamcommunity'); const SteamTotp = require('steam-totp'); const TradeOfferManager = require('steam-tradeoffer-manager'); const config = require('./config'); let client = new SteamUser(); let manager = new TradeOfferManager({ "steam": client, // Polling every 30 seconds is fine since we get notifications from Steam "domain": "example.com", // Our domain is example.com "language": "en" // We want English item descriptions }); let community = new SteamCommunity(); // Steam logon options let logOnOptions = { "accountName": config.accountName, "password": config.password, "twoFactorCode": SteamTotp.getAuthCode(config.shared_secret) }; client.logOn(logOnOptions); client.on('loggedOn', function() { console.log("Logged into Steam"); }); client.on('webSession', function(sessionID, cookies) { manager.setCookies(cookies, function() { manager.loadInventory(440, 2, true, function(err, inventory) { if (err) { console.log(err); return; } console.log("Found " + inventory.length + " Team Fortress 2 items"); console.log(inventory); var ref = 0; for (var i = 0; i < inventory.length; i++){ if(inventory[i].market_hash_name == 'Refined Metal'){ ref++ var metal = inventory[i].assetid; } } console.log(metal); if(ref >= 5){ //I want to send 5 metal when the bot backpack has enough metal in its backpack console.log('We have enough refined metal. Sending the trade'); let offer = manager.createOffer(config.bossID); offer.addMyItem(metal); offer.send(function(err, status) { if (err) { console.log(err); return; } if (status == 'pending') { console.log(`Offer #${offer.id} sent, but requires confirmation`); community.acceptConfirmationForObject(config.identity_secret, offer.id, function(err) { if (err) { console.log(err); } else { console.log("Offer confirmed"); } }); } else { console.log(`Offer #${offer.id} sent successfully`); } }); } }); }); community.setCookies(cookies); }); Charlie-81 1 Quote
Charlie-81 Posted February 6, 2019 Report Posted February 6, 2019 (edited) nice Edited February 6, 2019 by Charlie-81 Quote
Dr. McKay Posted February 6, 2019 Report Posted February 6, 2019 You should call addMyItem on the entire item object from the inventory, not just on the assetid. Otherwise, Steam has no idea what game you want to trade items from. Quote
TextDynasty Posted February 8, 2019 Author Report Posted February 8, 2019 You should call addMyItem on the entire item object from the inventory, not just on the assetid. Otherwise, Steam has no idea what game you want to trade items from. I modified the code a bit but it always sends me all its refined metal. How can I prevent this and only send a certain amount of metal? function sendref() { manager.loadInventory(440, 2, true, function (err, inventory){ if (err) { console.log(err); } else { // I need to send 5 ref var volume = 5; // Filter out all the ref var ref = inventory.filter(function (item) { return item.market_hash_name.match('Refined Metal') }); // Let the user know we don't have enough ref if (ref.length < volume) { console.log('Not enough ref'); return true; // Give up } // Start a new trade offer var offer = manager.createOffer(config.bossID); // Add what we should to the current trade console.log('Adding '+ref.length+' metal'); offer.addMyItems(ref); // Send the offer offer.send(function (err, status){ if (err) { console.log(err); } else if (status == 'pending'){ community.acceptConfirmationForObject(config.identity_secret, offer.id, function(err) { if (err) { console.log(err); } else { console.log("Offer confirmed"); } }); } else { console.log('Trade offer sent successfully'); } }); } }); } Quote
Dr. McKay Posted February 8, 2019 Report Posted February 8, 2019 inventory.filter is always going to return every item that matches the filter. If you only want to send some specific amount of metal, you should use slice, for example offer.addMyItems(ref.slice(0, 3)) to send 3. Quote
TextDynasty Posted February 8, 2019 Author Report Posted February 8, 2019 inventory.filter is always going to return every item that matches the filter. If you only want to send some specific amount of metal, you should use slice, for example offer.addMyItems(ref.slice(0, 3)) to send 3.Thanks that solved it const SteamUser = require('steam-user'); const SteamCommunity = require('steamcommunity'); const SteamTotp = require('steam-totp'); const TradeOfferManager = require('steam-tradeoffer-manager'); const config = require('./config'); let client = new SteamUser(); let manager = new TradeOfferManager({ "steam": client, // Polling every 30 seconds is fine since we get notifications from Steam "domain": "example.com", // Our domain is example.com "language": "en" // We want English item descriptions }); let community = new SteamCommunity(); // Steam logon options let logOnOptions = { "accountName": config.accountName, "password": config.password, "twoFactorCode": SteamTotp.getAuthCode(config.shared_secret) }; client.logOn(logOnOptions); client.on('loggedOn', function() { console.log("Logged into Steam"); }); client.on('webSession', function(sessionID, cookies) { manager.setCookies(cookies, function (err){ if (err) { console.log('Unable to set trade offer cookies: '+err); process.exit(1); // No point in staying up if we can't use trade offers } console.log('Trade offer cookies set.'); }); sendref(); community.setCookies(cookies); }); function sendref() { manager.loadInventory(440, 2, true, function (err, inventory){ if (err) { console.log(err); } else { // I need to send X ref var volume = ; //put whatever amount // Filter out all the ref var ref = inventory.filter(function (item) { return item.market_hash_name.match('Refined Metal') }); // Let the user know we don't have enough ref if (ref.length < volume) { console.log('Not enough ref'); return true; // Give up } // Start a new trade offer var offer = manager.createOffer(config.bossID); // Add what we should to the current trade console.log('Adding '+volume+' metal'); offer.addMyItems(ref.slice(0, volume)) // Send the offer offer.send(function (err, status){ if (err) { console.log(err); } else if (status == 'pending'){ community.acceptConfirmationForObject(config.identity_secret, offer.id, function(err) { if (err) { console.log(err); } else { console.log("Offer confirmed"); } }); } else { console.log('Trade offer sent successfully'); } }); } }); } 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.