【问题标题】:SyntaxError: Identifier 'client' has already been declared [closed]SyntaxError:标识符'client'已经被声明[关闭]
【发布时间】:2021-11-18 12:13:41
【问题描述】:

我试着做一个不和谐的机器人。每当我尝试用 cmd 运行它时,我都会得到这个:

cmd 中的错误:

C:\Users\kaalj\OneDrive\Desktop\Bot>node main.js
C:\Users\kaalj\OneDrive\Desktop\Bot\main.js:7
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
      ^

SyntaxError: Identifier 'client' has already been declared
←[90m    at wrapSafe (internal/modules/cjs/loader.js:988:16)←[39m
←[90m    at Module._compile (internal/modules/cjs/loader.js:1036:27)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:937:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m

到目前为止我得到的代码是: 包.json

{
  "name": "gerda",
  "version": "1.0.0",
  "description": "Gerda",
  "main": "= main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Jordy",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^13.1.0"
  }
}

main.js:

const Discord = require('discord.js');

const client = new Discord.Client();

const { Client, Intents } = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.once('ready', () => {
  console.log('Gerda is er');
});

client.login("Token");

有人知道我必须做什么才能让它运行吗? (在我的代码中,我实际上填写了我的令牌)

【问题讨论】:

  • 请不要发布代码图片,除非没有它们就无法表达。
  • 请不要将代码添加为图像。如果您发布最小、紧凑且可重现的代码 sn-p,人们将能够为您提供帮助。
  • 你只需要删除在第 3 行声明的client。所以删除第 3 行就可以了。
  • 欢迎来到 Stack Overflow!相关代码和错误消息需要包含在您的问题中作为文本,而不是作为文本图片。仅链接到屏幕截图会使人们更难帮助您。要了解有关此社区的更多信息以及我们如何为您提供帮助,请从 tour 开始并阅读 How to Ask 及其链接资源。

标签: javascript node.js discord discord.js


【解决方案1】:

正如您在第 3 行和第 7 行看到的那样,您在这两行上都声明了 const,它被称为:client。

就这么简单。

【讨论】:

    【解决方案2】:

    您只需删除在第 3 行声明的client。您已经在第 7 行详细处理了它。所以删除第 3 行就可以了。

    【讨论】:

      猜你喜欢
      • 2021-03-28
      • 1970-01-01
      • 2019-10-10
      • 1970-01-01
      • 2023-01-22
      • 2021-10-25
      • 2021-09-29
      • 1970-01-01
      • 2018-07-19
      相关资源
      最近更新 更多