【问题标题】:Dİscord.js on LinuxLinux 上的 Dİscord.js
【发布时间】:2021-07-31 03:06:42
【问题描述】:

我使用的是 Windows,现在我切换到了 Linux。使用 Windows 时,我使用“node bot.js”命令运行我的 discord.js 机器人。我无法在 Linux 上运行此命令。我使用命令“npm init”再次创建了机器人 ID,并创建了测试命令“node bot.js”,但我再次收到错误消息。我需要你的帮助。 (Linux Mint 64 位)

错误输出:/home/blour/Desktop/ew/node_modules/discord.js/src/client/Client.js:41

} catch {
        ^

SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/blour/Desktop/ew/node_modules/discord.js/src/index.js:8:11)

【问题讨论】:

  • 这是一个语法错误。请发帖minimal, reproducible example
  • 贴出你的Client.js的源代码。语法错误通常很容易发现,但为此我们需要完整的相关源代码。此外,如果代码在其他地方工作,则表明编程语言的语法已更改,因此在 Linux 和 Windows 上发布您的节点和 npm 版本很重要。您应该尝试将您的 Linux 节点/npm 与您的 Windows 匹配。

标签: javascript node.js linux discord discord.js


【解决方案1】:

我从您的错误中假设您正在尝试使用try/catch 语句,您需要为语句的catch 部分提供error 参数:

try {
// Do something
} catch (error) {
// Do something with 'error'
}

【讨论】:

    【解决方案2】:

    您的 try/catch 语句不完整。转到该文件并找到该行,在这些括号或类似的内容中找到一个console.error,然后在catch 之后和{ 之前添加(error)(将错误替换为console.error 中的对象)。

    【讨论】:

      【解决方案3】:

      您安装了旧版本的 nodejs。要将其重新安装到较新的版本,请使用:

      1. sudo apt-get purge --auto-remove nodejs
      2. sudo apt-get update
      3. sudo apt-get install build-essential libssl-dev
      4. curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
      5. source ~/.profile
      6. nvm install 14.17.4

      【讨论】:

        猜你喜欢
        • 2022-01-05
        • 2020-04-08
        • 2021-10-07
        • 2021-09-08
        • 1970-01-01
        • 2022-10-09
        • 1970-01-01
        • 2021-11-10
        • 2021-10-05
        相关资源
        最近更新 更多