Jump to content
McKay Development

Recommended Posts

Posted
node_modules\steam-tradeoffer-manager\lib\classes\TradeOffer.js:173
        items.forEach(function(item) {
              ^

TypeError: items.forEach is not a function

Got that error.

 

My code

manager.getInventoryContents(440, 2, true, function (err, inventory){
        if (err) {
            console.log(err);
        } else {
            // Filter out all the crates
            var pool = inventory.filter(function (item) {
                return item.name == "Reclaimed Metal"
            });

            // Let the user know we don't have any
            if (pool.length === 0) {
                client.chatMessage(steamID, 'I don\'t have available.  Sorry!');
                return true; // Give up
            } // Let the user know we don't have enough
            else if (amount > pool.length) {
                console.log('User requested '+amount+' of  I only have '+pool.length+' available.');
                client.chatMessage(steamID, 'I only have '+pool.length+' crates of series  available.  Sending a trade offer with all crates of this series.');
            }

            // Start a new trade offer
            var trade = manager.createOffer(steamID);

            // Add what we should to the current trade
            console.log('Adding '+ amount +' rec ');
            for (let i = 0; i < amount; i++) {
				trade.addMyItems(pool[i]);
			}


            // Send the offer off to Steam with a cute message
            trade.send();
        }
    });
Posted

Either call trade.addMyItem to add items one-by-one, or call trade.addMyItems on the entire pool to add them all at once.

 

addMyItem is for single items. addMyItems is for arrays of multiple items.

addMyItem solved my problem. Thanks and Merry Christmas

Posted (edited)

One more question. How to get the offerid?

 

 

Got this error

Offer Sent!! Check your trade offer by clicking here https://steamcommunity.com/tradeoffer/undefined . Feel free to contact my owner.
//it should be the id instead of undefined there.
               var token = manager.getOffer;

				// Add what we should to the current trade
				console.log("Adding " + amount + " rec.");
				for (let i = 0; i < amount; i++) {
					trade.addMyItem(pool[i]);
				}
				// Send the offer off to Steam with a cute message
				trade.send();
				community.startConfirmationChecker(15 * 1000, config.identity);
				client.chatMessage(steamID, "Offer Sent!! Check your trade offer by clicking here https://steamcommunity.com/tradeoffer/" + token.id + ". Feel free to contact my owner.");
Edited by TextDynasty
Posted

Well, for one thing, you're using token to store your TradeOffer, then calling trade.sent().

 

But your issue is that you aren't listening for the callback, you're just assuming it worked immediately. You need to pass a callback to send() and check the offer ID once it is called.

Posted

Well, for one thing, you're using token to store your TradeOffer, then calling trade.sent().

 

But your issue is that you aren't listening for the callback, you're just assuming it worked immediately. You need to pass a callback to send() and check the offer ID once it is called.

It fixed thanks. 

 

But when i run the code it just go this error

 

Code

function sendrec(steamID, amount) {
	if (!amount) {
        var amount = 1;
    }
	
	
manager.getUserInventoryContents(steamID, 440, 2, true, function (err, inventory){
	if (err) {
        console.log(err);
    } else {
        var scrap = inventory.filter(function (item) {
            return item.name == "Scrap Metal"
        });
			
			
		var NeededS = amount * 3
		var left = NeededS - amount
			
		if (scrap.length === 0){
			client.chatMessage(steamID, "It seems you don't have enough scrap.");
			return true;
		} else if (amount > NeededS) {
			client.chatMessage(steamID, "You don't have enough scrap. You'll need " + left + " more scrap metals.");
			return true;
		} else if (amount <= NeededS) {
			manager.getInventoryContents(440, 2, true, function (err, inventory){
				if (err) {
					console.log(err);
				} else {
					var pool = inventory.filter(function (item) {
							return item.name == "Reclaimed Metal"
					});

					// Let the user know we don't have any
					if (pool.length === 0) {
						client.chatMessage(steamID, "I don't have available.  Sorry!");
							return true;
					} else if (amount > pool.length) {
						console.log("User asked for more than my backpack.");
						client.chatMessage(steamID, "I only have " + pool.length + " available.  Sorry!");
						return true;
					} else if (amount <= pool.length) {
						// Start a new trade offer
						var trade = manager.createOffer(steamID);
						var token = manager.getOffer;			
						// Add what we should to the current trade
						console.log("Adding " + amount + " rec.");
						for (let i = 0; i < amount; i++) {
							trade.addMyItem(pool[i]);
						}
						for (let i = 0; i < NeededS; i++) {
							trade.addTheirItem(scrap[i]);
						}						
						
						// Send the offer off to Steam with a cute message
						trade.setMessage("Here is your " + amount + " reclaimed metals");
						trade.send(function(err, status) {
							if (err) {
								console.log(err);
									return;
							} if (status == 'pending') {
								console.log("Offer " + trade.id + "have been sent.");
								community.startConfirmationChecker(15 * 1000, config.identity);
								client.chatMessage(steamID, "Processing.");
								client.chatMessage(steamID, "Offer Sent!! Check your trade offer by here https://steamcommunity.com/tradeoffer/" + trade.id + "/.");
							} 
						});				
					}
				}
			});
		}
	}
})}

ERROR 

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...