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