TypeError: path.join不是一个函数(在我的handleEvents.js文件中得到了错误)



我试图使一个不和谐的机器人,我得到了这个错误在我的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));
}
}
}
}

相关内容

  • 没有找到相关文章

最新更新