I am trying to make a discord bot and i got this error in my handleEvents.js file
The code:
JavaScript
x
17
17
1
const { Client, Intents } = require('discord.js');
2
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
3
4
module.exports = (client) => {
5
client.handleEvents = async (eventFiles, path) => {
6
for (const file of eventFiles) {
7
const filePath = path.join(`${path}/${file}`);
8
const event = require(`../events/${file}`);
9
if (event.once) {
10
client.once(event.name, (args) => event.execute(args, client));
11
} else {
12
client.on(event.name, (args) => event.execute(args, client));
13
}
14
}
15
}
16
}
17
Advertisement
Answer
You are missing a path
module import
JavaScript
1
2
1
const path = require('path');
2
and by using the name path
as property of your callback, you would be overwriting the path
module.
JavaScript
1
18
18
1
const { Client, Intents } = require('discord.js');
2
const path = require('path');
3
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
4
5
module.exports = (client) => {
6
client.handleEvents = async (eventFiles, pathString) => {
7
for (const file of eventFiles) {
8
const filePath = path.join(`${pathString}/${file}`);
9
const event = require(`../events/${file}`);
10
if (event.once) {
11
client.once(event.name, (args) => event.execute(args, client));
12
} else {
13
client.on(event.name, (args) => event.execute(args, client));
14
}
15
}
16
}
17
}
18