如何修复 "event.bind is not a function"?

How to fix "event.bind is not a function"?

我正在设置一个新的 Discord 服务器,这意味着我需要为它制作一个新的自定义机器人。我正在重做 index.js 代码,然后我尝试第一次启动它,它告诉我 "event.bind is not a function"?问题出在哪里,我该如何解决?

我已经尝试重新安装 Node.js、Enmap 和 Discord.js,但问题不断出现。

fs.readdir("./events/", (err, files) => {
  if (err) return console.error(err);
  files.forEach(file => {
    const event = require(`./events/${file}`);
    const eventName = file.split(".")[0];
    client.on(eventName, event.bind(null, client));
  });
});

确保您的message.js是 module.exports = (client, message) => {

代码来自 https://anidiots.guide/first-bot/a-basic-command-handler#main-file-changes,因此您可能会在那里找到更多。

此外,加载程序不会检查文件是否为 .js 文件,因此请确保文件夹中只有 .js 文件。