Best practices for using Discord.js throughout different components
I'm working on breaking apart the single multiple thousand line .js source file I've been playing with for a while, I've seen some different advice (people saying to just make a new Discord client for each file, people exporting functions to interact with it, or exporting the client directly) and I'm not sure if my usecase is the same.
Right now, I'm just trying to get my server component separated (not related to D.js) but there are a few important events I like to log to a Discord channel (so I don't have to open any additional things to monitor it). The only thing I would like to export for my bot file is the channels I like to long to so I can call .send() on them.
I'm running into
Warning: Accessing non-existent property 'wgConsoleChannel' of module exports inside circular dependency
when loading my bot up, and Cannot read properties of undefined (reading 'send')
when calling wgConsoleChannel.send()
Should I export my bot, create some kind of interface for this kind of thing, or create a new Discord.Client in every file I need to do something like this?
I'd prefer the lightest weight possible option (within reason)
Thanks for reading :)2 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!the warning is because the channels are undefined when exporting ready event isnt fired yet), you can actually export client then get the chanel in that respective file when needed to avoid bugs