Node.Js 版本 14 抛出 e;不和谐机器人的错误(discord.js)

Posted

技术标签:

【中文标题】Node.Js 版本 14 抛出 e;不和谐机器人的错误(discord.js)【英文标题】:Node.Js version 14 throw e; error for discord bots (discord.js) 【发布时间】:2021-11-18 19:14:21 【问题描述】:

我从 GitHub 将 Discord music bot 分叉到 ReplIt,然后我尝试按照步骤成功运行机器人!

我使用 Node.JS v.14!

当我运行机器人时,我收到以下错误:

/home/runner/A-Advance-Discord-Music-Bot-Like-Hydra-/node_modules/bindings/bindings.js:121
        throw e;
        ^

Error: The module '/home/runner/A-Advance-Discord-Music-Bot-Like-Hydra-/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 88. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1151:18)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at bindings (/home/runner/A-Advance-Discord-Music-Bot-Like-Hydra-/node_modules/bindings/bindings.js:112:48)
    at Object.<anonymous> (/home/runner/A-Advance-Discord-Music-Bot-Like-Hydra-/node_modules/better-sqlite3/lib/database.js:9:24)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32) 
  code: 'ERR_DLOPEN_FAILED'

exit status 1

这是我的index.js 文件:


//Importing all needed Commands
const Discord = require("discord.js"); //this is the official discord.js wrapper for the Discord Api, which we use!
const colors = require("colors"); //this Package is used, to change the colors of our Console! (optional and doesnt effect performance)
const Enmap = require("enmap"); //this package is our Database! We will use it to save the data for ever!
const fs = require("fs"); //this package is for reading files and getting their inputs

//Creating the Discord.js Client for This Bot with some default settings ;) and with partials, so you can fetch OLD messages
const client = new Discord.Client(
  fetchAllMembers: false,
  restTimeOffset: 0,
  shards: "auto",
  restWsBridgetimeout: 100,
  disableEveryone: true,
  partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
  intents: ["GUILDS", "GUILD_MESSAGES"]
);

require('events').EventEmitter.defaultMaxListeners = 100;
process.setMaxListeners(100);

//Loading files, with the client variable like Command Handler, Event Handler, ...
["clientvariables", "command", "events", "erelahandler", "requestreacts"].forEach(handler => 
    require(`./handlers/$handler`)(client);
);

//Each Database gets a own file and folder which is pretty handy!
client.premium = new Enmap( name: "premium", dataDir: "./databases/premium" )
client.stats = new Enmap( name: "stats", dataDir: "./databases/stats" )
client.settings = new Enmap( name: "setups", dataDir: "./databases/settings" )
client.setups = new Enmap( name: "setups", dataDir: "./databases/setups" )
client.queuesaves = new Enmap( name: "queuesaves", dataDir: "./databases/queuesaves", ensureProps: false)
client.modActions = new Enmap( name: 'actions', dataDir: "./databases/warns" );
client.userProfiles = new Enmap( name: 'userProfiles', dataDir: "./databases/warns" );

//login into the bot
client.login(require("./botconfig/config.json").token);

谁能告诉我我的问题?

抱歉我的英语不好

【问题讨论】:

【参考方案1】:

要修复这个错误,我们需要彻底修复我们的 npm 内存!

    第一步,我们需要删除node_modules: $ rm -rf node_modules package-lock.json 然后清理我们的 npm 内存: $ npm cache clear --force $ npm cache clean --force 并重新安装它,以便在新版本中编译! npm install

我认为这会有所帮助!

【讨论】:

【参考方案2】:

您必须强制清理您的 npm 缓存并删除您的 node_modules 并重新安装它们以针对新的节点版本编译它们,同样您可以在控制台/Shell 中使用以下命令:

rm -rf node_modules && rm package-lock.json && npm cache clear --force && npm cache clean --force && npm install

【讨论】:

【参考方案3】:

好像你更新了Node.js版本,你可以用npm rebuild重建到新版本的Node.js然后启动应用程序,命令只使用一次而不是每次启动应用程序

【讨论】:

以上是关于Node.Js 版本 14 抛出 e;不和谐机器人的错误(discord.js)的主要内容,如果未能解决你的问题,请参考以下文章

为啥当我输入 node main.js 时我的不和谐机器人无法上线?

如何使不和谐机器人将消息发送到不和谐 Node js 的特定频道机器人

Node.js catch 语句返回不会停止执行

如何使用机器人删除不和谐的消息,但只能使用特殊角色 node.js

SyntaxError:在 Heroku 上托管 Discord 机器人时出现意外的令牌 '??='

我的不和谐机器人上的数据库(Discord.js + mysql)