Jump to content
McKay Development

Recommended Posts

Posted

Hey Guys, I'm currently having issues with my Bot. I send out trades and if the User declines it, I want to have feedback on that. The only problem I'm currently facing is the fact, that for some reason, the "receivedOfferCahnged" does not get triggered if the User declines the offer. Here is my code, thanks in advance!

manager.on('receivedOfferChanged', function(offer, oldState) {
    console.log(`Offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`);

    if (offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
        offer.getReceivedItems(function(err, items) {
            if (err) {
                console.log("Couldn't get received items: " + err);
            } else {
                var names = items.map(function(item) {
                    return item.name;
                });
                console.log("Received: " + names.join(', '));
                connection.query("UPDATE tradeoffer SET status='accepted' WHERE offerid='" + offer.id + "'", function(err, rows, fields) {
                    if (err) console.log(err);
                    postReq("accepted", offer.id);
                });
            }
        });
    }
    if (offer.state == TradeOfferManager.ETradeOfferState.Countered) {
        offer.decline();
        connection.query("UPDATE tradeoffer SET status='countered' WHERE offerid='" + offer.id + "'", function(err, rows, fields) {
            if (err) console.log(err);
            postReq("countered", offer.id);
        });
    }
    if (offer.state == TradeOfferManager.ETradeOfferState.Declined) {
        connection.query("UPDATE tradeoffer SET status='declined' WHERE offerid='" + offer.id + "'", function(err, rows, fields) {
            if (err) console.log(err);
            postReq("declined", offer.id);
        });
    }
    if (offer.state == TradeOfferManager.ETradeOfferState.InEscrow) {
        offer.decline();
        connection.query("UPDATE tradeoffer SET status='escrow' WHERE offerid='" + offer.id + "'", function(err, rows, fields) {
            if (err) console.log(err);
            postReq("escrow", offer.id);
        });
    }
    if (offer.state == TradeOfferManager.ETradeOfferState.InvalidItems) {
        connection.query("UPDATE tradeoffer SET status='invalid' WHERE offerid='" + offer.id + "'", function(err, rows, fields) {
            if (err) console.log(err);
            postReq("invalid", offer.id);
        });
    }
});

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