Error: Not Logged In
notuniq opened this issue · 1 comments
I have this problem while i send trade.
`const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');
const SteamID = require('steamid');
const Discord = require('discord.js');
const DiscordClient = new Discord.Client();
const config = require('./config.json');
const steamClient = new SteamUser();
const steamCommunity = new SteamCommunity();
const steamManager = new TradeOfferManager ({
steam: steamClient,
community: steamCommunity,
language: 'en'
});
const logOnOptions = {
accountName: config.steam.username,
password: config.steam.password,
twoFactorCode: SteamTotp.generateAuthCode(config.steam.sharedSecret)
};
steamClient.logOn(logOnOptions);
steamClient.on('loggedOn', () => {
console.log('succesfully logged on.');
steamClient.setPersona(SteamUser.EPersonaState.Online);
steamClient.gamesPlayed(["Custom Game",440]);
});
steamClient.on("friendMessage", function(steamID, message) {
if (message == "hi") {
steamClient.chatMessage(steamID, "hello, this works.");
}
});
steamClient.on('webSession', (sessionid, cookies) => {
steamManager.setCookies(cookies);
console.log('done')
steamCommunity.setCookies(cookies);
steamCommunity.startConfirmationChecker(20000, config.steam.identitySecret);
});
steamClient.setOption("promptSteamGuardCode", false);
DiscordClient.on('ready', () => {
console.log("Logged in as ${DiscordClient.user.tag}");
});
DiscordClient.on('message', async (message) => {
if (message.content === '!buy') {
// Проверяем, является ли сообщение личным сообщением или пришло в чат с названием, содержащим "ticket-"
if (message.channel.type === 'dm' || (message.channel.type === 'text' && message.channel.name.includes('ticket-'))) {
message.reply('Введите ваш Steam Trade Link');
const collector = new Discord.MessageCollector(message.channel, (m) => m.author.id === message.author.id, { time: 10000 });
collector.on('collect', async (msg) => {
const tradeLink = msg.content;
const params = new URL(tradeLink).searchParams;
const partnerID = params.get('partner');
const userSteamID = convertAccountIDToSteamID64(partnerID);
steamManager.getUserInventoryContents(userSteamID, 440, 2, true, (err, inventory) => {
if (err) {
console.log('Error getting user inventory:', err);
message.reply('Произошла ошибка при получении инвентаря :(');
} else {
const keyItem = inventory.find(item => item.market_hash_name === 'Mann Co. Supply Crate Key');
if (keyItem) {
const offer = steamManager.createOffer(tradeLink);
offer.addTheirItem(keyItem);
offer.setMessage('Thank you for your purchase!');
offer.send((err, status) => {
if (err) {
console.log('Error sending trade offer:', err);
message.reply('Произошла ошибка при отправке трейда :(');
} else if (status == 'pending') {
console.log('Trade offer sent successfully');
message.reply('Получите ваш Team Fortress 2 ключ');
} else {
console.log('Trade offer failed:', status);
message.reply('Произошла ошибка при отправке трейда :(');
}
});
} else {
console.log("User doesn't have Mann Co. Supply Crate Key in their inventory");
message.reply("У вас нет ключа Mann Co. Supply Crate Key в инвентаре");
}
}
});
collector.stop();
});
collector.on('end', (collected) => {
if (collected.size === 0) {
message.reply('Время истекло. Пожалуйста, попробуйте снова.');
}
});
}
}
});
DiscordClient.login(config.discord.token);
function convertAccountIDToSteamID64(accountID) {
const steamID = new SteamID.fromIndividualAccountID(accountID);
const steamID64 = steamID.getSteamID64();
return steamID64;
}`
npm update