【问题标题】:error message in discord bot(discord.js)?不和谐机器人(discord.js)中的错误消息?
【发布时间】:2021-10-19 03:32:09
【问题描述】:

所以我正在使用 discord.js,但在记事本中工作时犯了错​​误,现在我在运行以下命令时遇到内部错误:

client.on('message', async (message) => {
if (message.content == "help") {
    message.channel.send({embed: {
    color: 0,
    title: "Commands:",
    fields: [
    { name: "Commands", value: "help /support: \n help /games: \n help /commands:", inline: true},
    { name: "Actions", value: "Need help? Don't worry! \n Play a fun game or two. \n Need help with the basics? No problem.", inline: true}]}
});

我做错了什么?

错误是:

index.js:64
});


SyntaxError: Unexpected end of input
←[90m    at Object.compileFunction (node:vm:352:18)←[39m
←[90m    at wrapSafe (node:internal/modules/cjs/loader:1025:15)←[39m
←[90m    at Module._compile (node:internal/modules/cjs/loader:1059:27)←[39m
←[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)←[39m
←[90m    at Module.load (node:internal/modules/cjs/loader:975:32)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:816:12)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)←[39m
←[90m    at node:internal/main/run_main_module:17:47←[39m

谢谢!

【问题讨论】:

  • 看起来你对右括号/大括号感到困惑......似乎你错过了关闭 if 循环体?!使用更简洁的方式缩进代码以避免此类错误

标签: javascript node.js discord discord.js


【解决方案1】:

正如@suther 已经提到的,您的语法不正确。看看这个。您错过了一些大括号。

也许您还应该在 js 中使用严格相等比较运算符 === 而不是 == 进行相等检查,但在这种情况下它不是强制性的:

client.on('message', async (message) => {
  if (message.content === "help") {
    message.channel.send({
      embed: {
        color: 0,
        title: "Commands:",
        fields: [
          { 
            name: "Commands", 
            value: "help /support: \n help /games: \n help /commands:", 
            inline: true 
          },
          { 
            name: "Actions", 
            value: "Need help? Don't worry! \n Play a fun game or two. \n Need help with the basics? No problem.", 
            inline: true 
          }
        ]
      }
    });
  }
});

【讨论】:

  • 求助
猜你喜欢
  • 2021-07-13
  • 2021-08-04
  • 2018-11-19
  • 2021-07-30
  • 1970-01-01
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 2019-12-10
相关资源
最近更新 更多