How to import embeds from 1 file into 2 without creating embed in 2 file?
Let's say I have a config.json file in which I wrote 5 different embed messages. And there is info.js, which should output one of these messages depending on the role of the participant. How to do this, because I have an error with the fact that DiscordAPI requires minimal data in embed messages.
30 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 staff
What's the difference between importing json and js files?
Nothing, qjuh told you already. Whatever you are passing as an embed seems to be undefined, show your code specifically or json file structure and how you are importing/using it in the file
I'm importing embed messages from embed.js file. I had one version that the problem lay in .json.
I didn't quite understand how to do this. Can I get an example or a detailed explanation?
This is really a pretty basic JS thing, not discord.js
Don't overwrite module.exports
Do you know how to write an object?
No
:mdn: JavaScript object basics
Congratulations, you've reached the end of our first JS objects article — you should now have a good idea of how to work with objects in JavaScript — including creating your own simple objects. You should also appreciate that objects are very useful as structures for storing related data and functionality — if you tried to keep track of all the properties and methods in our person object as separate variables and functions, it would be inefficient and frustrating, and we'd run the risk of clashing with other variables and functions that have the same names. Objects let us keep the information safely locked away in their own package, out of harm's way.
I read the manual. I basically remembered how to do this because I had done it in other programming languages. But my problem is that I don’t know how not to overwrite the module, make a command and export the output of the embed message I need into it.
Just define module.exports once, with an object containing everything you want to export
Do not overwrite it. It's a variable like any other, you can't make it = things multiple times and expect it to merge itself
Where do I need to define it if I cannot create the command itself without it?
In your embed.js, your command file is fine. See how you doing there? Exporting
data
and execute
in one object? Do it like that in your embed file too
It boils down to basics module.exports= { A, B, ...}
Like this?
That's still your command file (and you also now removed the import for some reason)
?
I'm not sure what you are not understanding? The above image is great. Back to where we started ig. Did you fix your embed.js file though?
Now you got rid of your other variable entirely. But that'd work. Did you try it?
Also I recommend you freshen up your knowledge of js if you are struggling that much in basics #resources
The essence of the matter does not change. The exact same error is given. Sorry that I know so little in this area.
Show the full error please
Also how does your info.js looks now?
log
SOV_democracy
in your info.js file please
Better yet, just log console.log(require('./embed'))
The log shows completely different name than what you export from your embed.js file (
FRA_monarhist
). Are you sure your files are safe or did you make changes and forgot to uodate your imports?Please excuse me, I forgot to remove the export modules from other embed messages. I finally succeeded. Thank you for your help and your time. I would now like to clarify, is it possible to export the rest of the messages that I have in the same way?
That's what we have been telling you from start, yes. Export it as one object. Do not overwrite
module.exports
by doing it multiple times
...Once again thank you very much for your help!