Call client in another file
Hello !
I have my client instance declared in my index.ts as usual and would like to be able to call it in another file of my project and use it to send a message.
I'm listening for a twitch stream event, and would like to then send a message when this event trigger.
Any tips or documentation ?
Thanks !
10 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!You could have your client exported somewhere and import it everywhere you need it
Oh
so
In this, I could just replace const client... with export const client, then import it ?
looks like i'm accessing it from my other file when importing it, but then how would I create and send a message to a specific channel ? 🤔
You can't export in the index
You need to export from other file and import in the index
oh
Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View
yea i realised it would be much easier to use the ready event to do what i need afterall, thanks for your help guys !
Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View
no need for it to be a function
you can just
export const client = new Client(/*...*/);
Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View