我在YouTube上关注了教程/视频,我检查了代码并复制并粘贴了原始代码,但错误仍然存在。我该怎么办?
这是错误:
module.js:684
throw err;
^
SyntaxError: C:\Users\Galaxydragon7\Downloads\Giochi3\Bot\config.json: Unexpected string in JSON at position 167
at JSON.parse (<anonymous>)
at Object.Module._extensions..json (module.js:681:27)
at Module.load (module.js:575:32)
at tryModuleLoad (module.js:515:12)
at Function.Module._load (module.js:507:3)
at Module.require (module.js:606:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Galaxydragon7\Downloads\Giochi3\Bot\bot.js:5:16)
at Module._compile (module.js:662:30)
at Object.Module._extensions..js (module.js:673:10)
以下是代码:
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
const TradeOfferManager = require('steam-tradeoffer-manager');
const config = require('./config.json');
const client = new SteamUser();
const community = new SteamCommunity();
const manager = new TradeOfferManager ({
steam: client,
community: community,
language: 'it'
})
const logOnOptions = {
accountName: config.username,
password: config.password,
twoFactorCode: SteamTotp.generateAuthCode(config.sharedSecret)
};
client.logOn(logOnOptions);
client.on('loggedOn', () => {
console.log('succesfully logged on.');
client.setPersona(SteamUser.Steam.EPersonaState.Online);
client.gamesPlayed(["Custom Game",440]);
});
client.on("friendMessage", function(steamID, message) {
if (message == "hi") {
client.chatMessage(steamID, "hello, this works.");
}
});
client.on('webSession',(sessionid, cookies) => {
manager.setCookies(cookies);
community.setCookie(cookies);
community.startConfirmationChecker(20000, config.identitySecret);
});
function acceptOffer(offer) {
offer.accept((err) => {
community.checkConfirmation();
console.log("We accepted an offer");
if (err) console.log("There was an error accepting the offer");
});
}
function declineOffer(offer) {
offer.decline((err) => {
console.log("We declined an offer");
if (err) console.log("There was an error decling the offer");
});
}
client.setOption("promptSteamGuardCode", false);
manager.on('newOffer', (offer) => {
if (offer.partner.getSteamID64() === config.ownerID) {
acceptOffer(offer);
} else {
declineOffer(offer);
}
});
答案 0 :(得分:0)
{ &#34;用户名&#34;:&#34;&#34 ;, &#34;密码&#34;:&#34;&#34 ;, &#34; sharedSecret&#34;:&#34;&#34 ;, &#34; identitySecret&#34;:&#34;&#34; &#34; OWNERID&#34;:&#34;&#34; }
答案 1 :(得分:0)
JSON在最后一个键之前缺少逗号。错误是说JSON解析器期待逗号,但却看到了一个字符串。
{
"username": "",
"password": "",
"sharedSecret": "",
"identitySecret": "" // <-- here
"ownerID": ""
}