Javascript “如何修复”;词法声明不能出现在单个语句上下文中;
当我进行嵌入并运行bot时,此处出现问题,因为我使用了let embeddehelp=Discord.RichEmbed。此问题出现在终端中,请键入问题以及需要修复的内容:Javascript “如何修复”;词法声明不能出现在单个语句上下文中;,javascript,node.js,discord,Javascript,Node.js,Discord,当我进行嵌入并运行bot时,此处出现问题,因为我使用了let embeddehelp=Discord.RichEmbed。此问题出现在终端中,请键入问题以及需要修复的内容: SyntaxError: Lexical declaration cannot appear in a single-statement context at new Script (vm.js:79:7) at createScript (vm.js:251:10) at Object.runInThis
SyntaxError: Lexical declaration cannot appear in a single-statement context
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
我用于嵌入的代码是:
client.on('message', message => {
if (message.startsWith('$Commands'))
let EmbedHelp = Discord.RichEmbed()
"title": "title ~~(did you know you can have markdown here too?)~~",
"description": "```",
"url": "https://discordapp.com",
"color": 192748,
"timestamp": "Timezone - GGT 3+",
"footer": {
"icon_url": "https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png",
"text": "footer text"
},
"thumbnail": {
"url": "https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png"
},
"image": {
"url": "https://cdn.discordapp.com/embed/avatars/0.png"
},
"author": {
"name": "Galak$y#3038",
"url": "https://discordapp.com",
"icon_url": "https://discordapp.com/channels/564059839320555540/569179399211974666"
},
}
});
channel.send({EmbedHelp})
该错误指的是
Discord.RichEmbed()
下面的行。您有一个对象属性声明,但看不到任何对象。看起来你把一些你想从Discord docs中得到的东西混在一起了
旨在与其他助手方法链接。如果您将代码放入一个对象中(用大括号括起来)并将其传递到一个send
方法中,那么应该可以消除该错误
client.on('message', message => {
if (message.startsWith('$Commands')) {
message.channel.send({ embed: {
"title": "title ~~(did you know you can have markdown here too?)~~",
"description": "```",
"url": "https://discordapp.com",
"color": 192748,
"timestamp": "Timezone - GGT 3+",
"footer": {
"icon_url": "https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png",
"text": "footer text"
},
"thumbnail": {
"url": "https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png"
},
"image": {
"url": "https://cdn.discordapp.com/embed/avatars/0.png"
},
"author": {
"name": "Galak$y#3038",
"url": "https://discordapp.com",
"icon_url": "https://discordapp.com/channels/564059839320555540/569179399211974666"
},
}});
}
});
我有以下代码:
let viewShareSelectBoxInitializedInterval = setInterval(function () {
if (IsViewShareSelectBoxInitialized() === true) {
clearInterval(viewShareSelectBoxInitializedInterval);
ReloadViewShareItems(endItemStateIdForSharing);
}
}, 250);
我将let
更改为var
,然后工作正常
在我的开发机器上,它可以与
let
一起工作,但是当JavaScript与let
捆绑在一起时,它会失败。这就是它所说的<代码>如果(…)让嵌入式帮助=代码>无效。你想让条件做什么?而且embeddehelp
下的整个部分应该在映射中吗?如果你在If
中放入多个语句,你需要{}
围绕它们。。。。如果您没有在if
中放入多个语句,那么let
声明几乎毫无意义