Jump to content
McKay Development

Callback is not a function


Recommended Posts

I am currently creating a TF2 trading bot and I want it to be able to send trade offers but i keep getting this error 

C:\Users\Valkyrie\Desktop\Trading Bot\node_modules\steamcommunity\components\users.js:491
                                callback(null, inventory, currency, body.total_inventory_count);

My main code is

client.on("friendMessage", function(steamID, message) {
	if (message == "!buy test item") {
		client.chatMessage(steamID, "Setting up the trade offer for Test Item");
		console.log("Someone typed in the command '!buy test item'");
		const offer = manager.createOffer(steamID);
		manager.loadInventory(440, 2, true, (err, inventory) => {
			if (err) {
				client.chatMessage("There was an error loading the inventory. Please try again. If the problem continues please message the owner by typing '!help'");
				console.log(err);
				console.log("There was an error loading my inventory.");
			} else {
				offer.getPartnerInventoryContents(440, 2, true, (err, inventory) => {
					if (err) {
						client.chatMessage("There was an error loading the inventory. Please try again. If the problem continues please message the owner by typing '!help'");
						console.log(err);
						console.log("There was an error loading their inventory.");
					} else {
						const offer = manager.createOffer(76561198083465811);
						inventory.forEach(function(item) {
							if (item.assetid === '30362') {
								offer.addMyItem(item);
								offer.addTheirItems(5002, 5002, 5001, 5001, 5000, 5000);
								offer.setMessage("1 Law for 2.88 Refined");
								offer.send(function(err, status) {
									if (err) {
										client.chatMessage("There was an error sending the trade offer. Please try again. If the problem continues please message the owner by typing '!help'");
										console.log(err);
										console.log("There was an error sending the trade offer.");
									} else {
										console.log(status);
										console.log("The trade was sent successfully!");
									}
								})
							}
						})
					}
				})
			}
		})
	}
})

 

Link to comment
Share on other sites

1 hour ago, Dr. McKay said:

You've cut out the actual error message.

C:\Users\Valkyrie\Desktop\Trading Bot\node_modules\steamcommunity\components\users.js:491
                                callback(null, inventory, currency, body.total_inventory_count);
                                ^

TypeError: callback is not a function
    at SteamCommunity.<anonymous> (C:\Users\Valkyrie\Desktop\Trading Bot\node_modules\steamcommunity\components\users.js:491:5)
    at Request._callback (C:\Users\Valkyrie\Desktop\Trading Bot\node_modules\steamcommunity\components\http.js:67:15)
    at Request.self.callback (C:\Users\Valkyrie\Desktop\Trading Bot\node_modules\request\request.js:185:22)
    at Request.emit (events.js:310:20)
    at Request.<anonymous> (C:\Users\Valkyrie\Desktop\Trading Bot\node_modules\request\request.js:1154:10)
    at Request.emit (events.js:310:20)
    at Gunzip.<anonymous> (C:\Users\Valkyrie\Desktop\Trading Bot\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (events.js:416:28)
    at Gunzip.emit (events.js:322:22)
    at endReadableNT (_stream_readable.js:1187:12)

Link to comment
Share on other sites

You defined offer variable twice in your code as constant please fix that.

And  for your problem

offer.getPartnerInventoryContents(440, 2, (err, inventory,currency) => {

}

this should fix it yours has 4 inputs for some reason.

Edited by Perport
Link to comment
Share on other sites

On 5/12/2020 at 1:52 AM, Perport said:

You defined offer variable twice in your code as constant please fix that.

And  for your problem


offer.getPartnerInventoryContents(440, 2, (err, inventory,currency) => {

}

this should fix it yours has 4 inputs for some reason.

This is a problem and another problem is you are using the same name for loading both inventories. `loadInventory` and `getPartnerInventoryContents` both are using the same callback name `inventory`. This is making the code break

Link to comment
Share on other sites

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...