typeerror:path.join不是一个函数(在我的handingevents.js文件中获取错误)

发布于 2025-02-02 13:30:18 字数 713 浏览 2 评论 0原文

我正在尝试制作一个Discord bot,并且在handingevents.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));
            }
        }
}
}

I am trying to make a discord bot and i got this error in my handleEvents.js file

The code:

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));
            }
        }
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2025-02-09 13:30:18

您缺少路径模块导入

const path = require('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));
            }
        }
    }
}

You are missing a path module import

const path = require('path');

and by using the name path as property of your callback, you would be overwriting the path module.

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));
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文