const SteamUser = require('steam-user');
const SteamTradeOfferManager = require('steam-tradeoffer-manager');
const SteamTotp = require('steam-totp');
// Your Steam account credentials
const username = 'username';
const password = 'password';
const sharedSecret = 'secret'; // Your Steam shared secret
// Initialize SteamUser bot instance
const bot = new SteamUser();
// Initialize TradeOfferManager
let manager;
// Handle successful login
bot.on('loggedOn', () => {
console.log('Logged into Steam!');
// Initialize the TradeOfferManager
manager = new SteamTradeOfferManager({
steam: bot,
domain: 'localhost',
language: 'en',
});
console.log('TradeOfferManager initialized!');
// Fetch bot's inventory (use appid 440 as an example for Team Fortress 2 items)
const appId = 440; // Use the appid for the game you want the inventory for (e.g., 440 for TF2)
const contextId = '2'; // Default context for TF2 (can be different for other games)
manager.getInventoryContents(appId, contextId, true, (err, inventory) => {
if (err) {
console.log('Error fetching inventory:', err);
} else {
console.log('Bot inventory fetched successfully!');
console.log(inventory); // Log the inventory to the console
}
// After fetching the inventory, log out the bot
bot.logOff();
});
});
// This event is triggered when Steam requires the Steam Guard code (2FA)
bot.on('loginKey', (loginKey) => {
console.log('Received loginKey, generating 2FA code...');
// Generate the 2FA code using the shared secret
const twoFactorCode = SteamTotp.generateAuthCode(sharedSecret);
console.log('Generated Steam Guard App Code (2FA Code):', twoFactorCode); // Logs the generated 2FA code to the console
// Log in again with the 2FA code
bot.login({
accountName: username,
password: password,
twoFactorCode: twoFactorCode, // Pass the generated 2FA code
});
});
// Handle login errors
bot.on('error', (err) => {
console.log('Error during login:', err);
});
// Handle login attempts
bot.on('steamGuard', (domain, callback) => {
console.log('Steam Guard is required!');
// Check if Steam Guard is enabled
const twoFactorCode = SteamTotp.generateAuthCode(sharedSecret);
console.log('Sending 2FA code:', twoFactorCode);
// Send the 2FA code to Steam Guard for login
callback(twoFactorCode);
});
// Start the login process
bot.logOn({
accountName: username,
password: password,
});
Console log:
Steam Guard is required!
Sending 2FA code: MYXV5
Logged into Steam!
TradeOfferManager initialized!
Error fetching inventory: Error: Not Logged In
I replaced all the credentials, steam guard passes, it logs in, and then when I try to fetch inventory it says I am not logged in to the account.