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.
No description
No description
31 Replies
d.js toolkit
d.js toolkit4d ago
- 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 staff
LuisTTV
LuisTTVOP4d ago
Versions: [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.
LuisTTV
LuisTTVOP4d ago
This isnt working
No description
LuisTTV
LuisTTVOP4d ago
This is the full error
No description
treble/luna
treble/luna4d ago
And did you specify them in your client constructor
LuisTTV
LuisTTVOP4d ago
I did
treble/luna
treble/luna3d ago
I also dont see you passing client anywhere, those 2 functions are not related Show it
LuisTTV
LuisTTVOP3d ago
No description
LuisTTV
LuisTTVOP3d ago
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
NyR
NyR3d ago
You are missing GuildMessages intent Wdym by that? Where's your XpOrTimeout function is called? You are likely not passing in client
LuisTTV
LuisTTVOP3d ago
Oh yeah that fixed my eventhandling issue at least, thanks.
LuisTTV
LuisTTVOP3d ago
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
No description
LuisTTV
LuisTTVOP3d ago
so im not sure if i can pass a value when calling a file and not a function
NyR
NyR3d ago
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
d.js docs
d.js docs3d ago
To share long code snippets, use a service like gist, sourcebin, pastebin, or similar instead of posting them as large code blocks or files.
LuisTTV
LuisTTVOP3d ago
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.
NyR
NyR3d ago
So yeah, daily is indeed XpOrTimeout, since that's the default export. Just pass the client when calling it
LuisTTV
LuisTTVOP3d ago
Im now getting this error
No description
NyR
NyR3d ago
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?
d.js docs
d.js docs3d ago
discord.js includes multiple sub-packages, installing these separately can mess with internal code:
npm uninstall discord-api-types @discordjs/rest @discordjs/builders
yarn remove discord-api-types @discordjs/rest @discordjs/builders
pnpm remove discord-api-types @discordjs/rest @discordjs/builders
npm uninstall discord-api-types @discordjs/rest @discordjs/builders
yarn remove discord-api-types @discordjs/rest @discordjs/builders
pnpm remove discord-api-types @discordjs/rest @discordjs/builders
NyR
NyR3d ago
This also is relevant to you ^
LuisTTV
LuisTTVOP3d ago
Got parts of it from ChatGPT lmao
NyR
NyR3d ago
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
LuisTTV
LuisTTVOP3d ago
I now fixed this but im already getting another error XD
No description
LuisTTV
LuisTTVOP3d ago
Yeah it seems to not be helpful in this case, however for other programming projects I find it kinda useful
LuisTTV
LuisTTVOP3d ago
Im now getting this error tho, I dont understand what this even means XD
No description
NyR
NyR3d ago
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 one
LuisTTV
LuisTTVOP3d ago
Oh okay thanks
NyR
NyR3d ago
Button style is a number, not a string, use the ButtonStyle enum
d.js docs
d.js docs3d ago
:dtypes: v10: ButtonStyle - Primary read more
LuisTTV
LuisTTVOP3d ago
Everything seems to work now, thank you very much for your help, appreciate it!
Want results from more Discord servers?
Add your server