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