function is not a function???

client.on(eventName, async (arg) => {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, arg);
}
})
client.on(eventName, async (arg) => {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, arg);
}
})
how to fix this?
37 Replies
d.js toolkit
d.js toolkit•11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
$ MattX
$ MattX•11mo ago
node:events:491 throw er; // Unhandled 'error' event ^ TypeError: eventFunction is not a function at Client.<anonymous> (C:\Users\matti\OneDrive\Desktop\spyro\src\handlers\eventHandler.js:16:23) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Emitted 'error' event on Client instance at: at emitUnhandledRejectionOrErr (node:events:394:10) at process.processTicksAndRejections (node:internal/process/task_queues:84:21) Node.js v18.16.1 this is the error
treble/luna
treble/luna•11mo ago
and how did you define eventFunction
$ MattX
$ MattX•11mo ago
wait im gonna send u one moment i didnt i dont know how to use this
treble/luna
treble/luna•11mo ago
how to use what
$ MattX
$ MattX•11mo ago
i defined it on const eventFunction but i dont know if it means defining im new to this language
treble/luna
treble/luna•11mo ago
and does the file you import export anything
$ MattX
$ MattX•11mo ago
this one or other files in my code space ?
treble/luna
treble/luna•11mo ago
the one you try to import your 'eventFile'
$ MattX
$ MattX•11mo ago
it's not a file it'a const referred to other files
treble/luna
treble/luna•11mo ago
sigh require is importing a file so your eventFunction is whatever your file exports
$ MattX
$ MattX•11mo ago
lets do a thing i send u all the file in exam so u can see
treble/luna
treble/luna•11mo ago
just send the file you are trying to import since you're new i assume you dont have many files
$ MattX
$ MattX•11mo ago
const getAllFiles = require("../utils/getAllFiles")
const path = require('path')

module.exports = (client) => {
const eventFolders = getAllFiles(path.join(__dirname, '..', 'events'), true)

for (const eventFolder of eventFolders) {
const eventFiles = getAllFiles(eventFolder);
eventFiles.sort((a, b) => a > b)

const eventName = eventFolder.replace(/\\/g, '/').split('/').pop()

client.on(eventName, async (arg) => {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, arg);
}
})
}
}
const getAllFiles = require("../utils/getAllFiles")
const path = require('path')

module.exports = (client) => {
const eventFolders = getAllFiles(path.join(__dirname, '..', 'events'), true)

for (const eventFolder of eventFolders) {
const eventFiles = getAllFiles(eventFolder);
eventFiles.sort((a, b) => a > b)

const eventName = eventFolder.replace(/\\/g, '/').split('/').pop()

client.on(eventName, async (arg) => {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, arg);
}
})
}
}
can u tell me what's wrong in this?
treble/luna
treble/luna•11mo ago
ok thats not what im asking. do any of the files in your eventFolder export anything
$ MattX
$ MattX•11mo ago
yes just the client and an argument (interaction)
treble/luna
treble/luna•11mo ago
console.log your eventfucntion, without (), before calling it
$ MattX
$ MattX•11mo ago
ok im trying now the same error @luna🌈
treble/luna
treble/luna•11mo ago
yeah show the output of that console.log
$ MattX
$ MattX•11mo ago
.
treble/luna
treble/luna•11mo ago
no
$ MattX
$ MattX•11mo ago
no wait
treble/luna
treble/luna•11mo ago
thats not the output
$ MattX
$ MattX•11mo ago
yeah sorry . this one
treble/luna
treble/luna•11mo ago
thats the error i asked what the console.log returned
$ MattX
$ MattX•11mo ago
he returned that i just did it and it showed me the error again
treble/luna
treble/luna•11mo ago
and whats above your error
$ MattX
$ MattX•11mo ago
nothing my command
treble/luna
treble/luna•11mo ago
show the log
$ MattX
$ MattX•11mo ago
Spyro#9186 è online this is the only thing above the error
treble/luna
treble/luna•11mo ago
just send a screenshot
$ MattX
$ MattX•11mo ago
idk what to say
treble/luna
treble/luna•11mo ago
how many files are in your eventfolder
$ MattX
$ MattX•11mo ago
$ MattX
$ MattX•11mo ago
2 folders: 1) 1 file 2) 2 files
$ MattX
$ MattX•11mo ago
treble/luna
treble/luna•11mo ago
can you console.log the eventfile