Import client variable in a SlashCommandBuilder function
Hello, i'm trying to use the client variable inside a command but its not accessible.
11 Replies
• 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.In the client constructor i have my database settings
This is how i use it in the default files
but here in the slash commands i dont have the client like in the other files
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Tried to use interaction.client but it does not have the db parameter
We highly recommend you extend the
Client
structure properly instead of just attaching custom properties like .commands
to the regular discord.js Client
instance.
• Using typescript, you might want to consider casting or augmenting the module typeUsing javascript
Why it is not properly extending?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Using: interaction.client.db.query
Error: Cannot read properties of undefined (reading 'query')
The custom property i added does not exist here
But i'm not understanding why
It isnt this one? line 29
Thank you. Your question clarified my mind and i figure out that i have a file DeploySlash.js that instantiate the client without adding the .db property
Not the best solution, but adding the db there works 😄
Using a custom class is a way better but it is how it is because it was the way i found to make it work. That code was made some years ago its a bit outdated nor using the best practices
I learned much over the years
Maybe add the custom client to the parameters when executing the method