client is undefined error
Hey, I have the problem that I get an error with "client is undefined" after I call my script via "const script = require("./src/script"); script()". I have attached screenshots of the problem.
31 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by staffVersions:
[email protected]
node v21.6.2
Furthermore, I also have a problem with the "messageCreate" event handling, I have set all the necessary intents in the script and in the Discord Developer Portal but it simply does not respond to "messageCreate", but other events like "ready" work.
This isnt working
This is the full error
And did you specify them in your client constructor
I did
I also dont see you passing client anywhere, those 2 functions are not related
Show it
The thing is that im not calling a function but a script so im not sure if I can even pass a parameter into a script
You are missing
GuildMessages
intent
Wdym by that? Where's your XpOrTimeout
function is called? You are likely not passing in clientOh yeah that fixed my eventhandling issue at least, thanks.
Im calling this "daily" in my index.js, however the "daily" is a script and not a function, the function that is throwing the error is the "XpOrTimeout" in the "daily" script
so im not sure if i can pass a value when calling a file and not a function
You don't call a script, you call a function, without calling
XpOrTimeout
, it'll not run, depending on how you export from that file, your daily
might just be that, please show full code of your levelupOrTimeout
Pastebin
const { EmbedBuilder } = require("@discordjs/builders");const { Mes...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
So yeah,
daily
is indeed XpOrTimeout
, since that's the default export. Just pass the client when calling itIm now getting this error
It is indeed not, it's
ActionRowBuilder
in v14
And ButtonBuilder
, not MessageButton
, your code looks mix of v13 and v14, where are you getting this from?discord.js includes multiple sub-packages, installing these separately can mess with internal code:
This also is relevant to you ^
Got parts of it from ChatGPT lmao
Please don't, AI is known to give outdated codes, thats why we have guides to help you and docs for stuff you may need, if you have confusion, you can always ask here
I now fixed this but im already getting another error XD
Yeah it seems to not be helpful in this case, however for other programming projects I find it kinda useful
Im now getting this error tho, I dont understand what this even means XD
Also, i notice you creating an interactionCreate listener inside the XpOrTimeout function, that is a bad idea which will pretty soon lead to memory leak considering you call thay function in cron job, if you need a temporary listener, use a collector, otherwise handle it in your main
interactionCreate
event listener, you only ideally need oneOh okay thanks
Button style is a number, not a string, use the
ButtonStyle
enumEverything seems to work now, thank you very much for your help, appreciate it!