TypeError: path.join is not a function (got the error in my handleEvents.js file)

TypeError: path.join is not a function (got the error in my handleEvents.js file)

我正在尝试制作一个不和谐的机器人,但我的 handleEvents.js 文件中出现了这个错误

代码:

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

module.exports = (client) => {
    client.handleEvents = async (eventFiles, path) => {
        for (const file of eventFiles) {
            const filePath = path.join(`${path}/${file}`);
            const event = require(`../events/${file}`);
            if (event.once) {
                client.once(event.name, (...args) => event.execute(...args, client));
            } else {
                client.on(event.name, (...args) => event.execute(...args, client));
            }
        }
}
}

您缺少 path 模块导入

const path = require('path');

并且通过使用名称 path 作为回调的 属性,您将覆盖 path 模块。

const { Client, Intents } = require('discord.js');
const path = require('path');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

module.exports = (client) => {
    client.handleEvents = async (eventFiles, pathString) => {
        for (const file of eventFiles) {
            const filePath = path.join(`${pathString}/${file}`);
            const event = require(`../events/${file}`);
            if (event.once) {
                client.once(event.name, (...args) => event.execute(...args, client));
            } else {
                client.on(event.name, (...args) => event.execute(...args, client));
            }
        }
    }
}