2

I'm having problems with constants in different files: I have to store an embed in a different file, and then call it in the main one, but when I try to do it gives me parse errors like Unexpected '.' in 'help.embed' I tried to use the methods suggested in these threads [1,2] but they didn't work: it continues to give me that parse error. Can somebody help me?
PS: I don't want to use an HTML file to call the scripts, I want to use only JS and JSON

This is my code (simplified):

// help.js
const Discord = require("discord.js");

var embed = new Discord.RichEmbed()
  .setTitle("Title")

module.exports = Object.freeze({
  embed: embed
});
// main.js
const help = require("./help.js")
client.on("ready", () =>{
  client.channels.find("id",config.disaply_channel).send(help.embed); //Parse error
});
Federico Grandi
  • 6,048
  • 4
  • 23
  • 41
  • Are you sure the `help` object is coming through properly? Do you see the `embed` property when you log it to the console? – glhrmv Jun 26 '17 at 11:11
  • Try `.send({help.embed})` – Wright Jun 26 '17 at 18:04
  • I logged the help object and I clearly see the embed property, with the type RichEmbed. I tried also to log only the help.embed and it's a normal object. But when I tried to send it, it returned "Unable to send empty message"or a thing like that – Federico Grandi Jun 27 '17 at 08:53

1 Answers1

0

I found out that if the command was in the same file as the embed I should use message.channel.send({embed}), so I tried to send help.{embed}, but it gave me a fatal error. I resolved declaring the export embed: {embed} instead of only embed: embed, and then calling help.embed in the main file. Thank you for your support anyway

Federico Grandi
  • 6,048
  • 4
  • 23
  • 41