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•2y 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
$ MattXOP•2y 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•2y ago
and how did you define eventFunction
$ MattX
$ MattXOP•2y ago
wait im gonna send u one moment i didnt i dont know how to use this
treble/luna
treble/luna•2y ago
how to use what
$ MattX
$ MattXOP•2y ago
i defined it on const eventFunction but i dont know if it means defining im new to this language
treble/luna
treble/luna•2y ago
and does the file you import export anything
$ MattX
$ MattXOP•2y ago
this one or other files in my code space ?
treble/luna
treble/luna•2y ago
the one you try to import your 'eventFile'
$ MattX
$ MattXOP•2y ago
it's not a file it'a const referred to other files
treble/luna
treble/luna•2y ago
sigh require is importing a file so your eventFunction is whatever your file exports
$ MattX
$ MattXOP•2y ago
lets do a thing i send u all the file in exam so u can see
treble/luna
treble/luna•2y ago
just send the file you are trying to import since you're new i assume you dont have many files
$ MattX
$ MattXOP•2y 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•2y ago
ok thats not what im asking. do any of the files in your eventFolder export anything
$ MattX
$ MattXOP•2y ago
yes just the client and an argument (interaction)
treble/luna
treble/luna•2y ago
console.log your eventfucntion, without (), before calling it
$ MattX
$ MattXOP•2y ago
ok im trying now the same error @luna🌈
treble/luna
treble/luna•2y ago
yeah show the output of that console.log
$ MattX
$ MattXOP•2y ago
.
treble/luna
treble/luna•2y ago
no
$ MattX
$ MattXOP•2y ago
no wait
treble/luna
treble/luna•2y ago
thats not the output
$ MattX
$ MattXOP•2y ago
yeah sorry . this one
treble/luna
treble/luna•2y ago
thats the error i asked what the console.log returned
$ MattX
$ MattXOP•2y ago
he returned that i just did it and it showed me the error again
treble/luna
treble/luna•2y ago
and whats above your error
$ MattX
$ MattXOP•2y ago
nothing my command
treble/luna
treble/luna•2y ago
show the log
$ MattX
$ MattXOP•2y ago
Spyro#9186 è online this is the only thing above the error
treble/luna
treble/luna•2y ago
just send a screenshot
$ MattX
$ MattXOP•2y ago
idk what to say
treble/luna
treble/luna•2y ago
how many files are in your eventfolder
$ MattX
$ MattXOP•2y ago
$ MattX
$ MattXOP•2y ago
2 folders: 1) 1 file 2) 2 files
$ MattX
$ MattXOP•2y ago
treble/luna
treble/luna•2y ago
can you console.log the eventfile

Did you find this page helpful?