Discord.js Bot运行时出现隐形标识符异常问题咨询
The immediate issue here is your variable name — you can’t have spaces in JavaScript variable declarations. Let’s break this down:
The Root Cause
Your line of code:
var Demanding Boss = "**Demanding Boss:** Your pushing of minions with healthy competition has caused unhealthy competition"
The space between Demanding and Boss violates JavaScript’s variable naming rules. Variables can only include letters, numbers, underscores (_), or dollar signs ($), and can’t start with a number or contain spaces.
When the parser hits that space, it interprets Demanding as one identifier and Boss as another, leading to a syntax error that might show up as an "invisible identifier" exception (since the parser doesn’t recognize what Boss is doing there without a valid context like an assignment operator).
The Fix
Rename your variable to a valid format. Here are a few common options:
- CamelCase:
var demandingBoss = "**Demanding Boss:** Your pushing of minions with healthy competition has caused unhealthy competition" - Snake_case:
var demanding_boss = "**Demanding Boss:** Your pushing of minions with healthy competition has caused unhealthy competition" - PascalCase (often used for classes, but still valid):
var DemandingBoss = "**Demanding Boss:** Your pushing of minions with healthy competition has caused unhealthy competition"
Once you update the variable name to remove the space, that syntax error should disappear, and your Discord.js bot should run as expected.
内容的提问来源于stack exchange,提问作者Cate

