Node.js ';常数';没有定义
嗨,我需要一些帮助再次与我的不和谐缓和机器人。这是机器人背后的代码。(我说出了错误的部分。) 我不明白为什么机器人会在const commandbody上坏掉。 有人能帮我吗? 错误:Node.js ';常数';没有定义,node.js,discord.js,Node.js,Discord.js,嗨,我需要一些帮助再次与我的不和谐缓和机器人。这是机器人背后的代码。(我说出了错误的部分。) 我不明白为什么机器人会在const commandbody上坏掉。 有人能帮我吗? 错误: const commandBody = message.content.slice(prefix.length); ^^^^^ SyntaxError: Unexpected token 'const' at Object.compileFunction (node:vm:355:18)
const commandBody = message.content.slice(prefix.length);
^^^^^
SyntaxError: Unexpected token 'const'
at Object.compileFunction (node:vm:355:18)
at wrapSafe (node:internal/modules/cjs/loader:1039:15)
at Module._compile (node:internal/modules/cjs/loader:1073:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
试试
var
,看看它是否有效。我不明白为什么const是意外的,因为它看起来语法不错。也许包装你的返回{and}中的code>s?而不是message.content==..
我至少会更改为message.content.toLowerCase()。includes(…)
。为了涵盖更多的情况,我会做一个函数,可以检查一堆不同拼写的单词。。。可能来自一个可以轻松更新的文件,尽管它与您当前的问题无关:仅使用一个消息事件,使用2个或更多消息事件将导致内存泄漏。好的,我发现了错误,它在我的文件中。导致问题的线路不是const commandBody。而是缺少返回的if(!message.content.startsWith(prefix));
const commandBody = message.content.slice(prefix.length);
^^^^^
SyntaxError: Unexpected token 'const'
at Object.compileFunction (node:vm:355:18)
at wrapSafe (node:internal/modules/cjs/loader:1039:15)
at Module._compile (node:internal/modules/cjs/loader:1073:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47