pochiko - Hello! does anyone kno whow to fix this ...

Hello! does anyone kno whow to fix this problem? ive been trying to figure out why for the past 30 minutes
Function.prototype.apply was called on undefined, which is a undefined and not a function

my code is here:

const fs = require('fs');

module.exports = (client) => {
client.handleEvents = async () => {
const eventFolders = fs.readdirSync(`./src/events`);
for (const folder of eventFolders) {
const eventFiles = fs
.readdirSync(`./src/events/${folder}`)
.filter((file) => file.endsWith(".js"));
switch (folder) {
case "client":
for (const file of eventFiles) {
const event = require(`../../events/${folder}/${file}`);
if (event.once) client.once(event.name, (...args) => event.execute(...args, client));
else client.on(event.name, (...args) => event.execute(...args, client));
}
break;

default:
break;
}
}
}

}
Function.prototype.apply was called on undefined, which is a undefined and not a function

my code is here:

const fs = require('fs');

module.exports = (client) => {
client.handleEvents = async () => {
const eventFolders = fs.readdirSync(`./src/events`);
for (const folder of eventFolders) {
const eventFiles = fs
.readdirSync(`./src/events/${folder}`)
.filter((file) => file.endsWith(".js"));
switch (folder) {
case "client":
for (const file of eventFiles) {
const event = require(`../../events/${folder}/${file}`);
if (event.once) client.once(event.name, (...args) => event.execute(...args, client));
else client.on(event.name, (...args) => event.execute(...args, client));
}
break;

default:
break;
}
}
}

}
2 Replies
Favna
Favna2y ago
This channel is for support with the Sapphire framework. Your code however is not that. It appears you are writing your own event handler. If you insist on using your own framework, please seek support elsewhere as seeking it here is implicitly saying you do not approve of Sapphire.
pochiko
pochiko2y ago
oh sorry im new to coding so im not really sure where do i seek help for all this, i didnt mean to disapprove of sapphire