Skip to content
Advertisement

How to import a discord embed from another file

I’m making a discord bot that posts embeds based on commands. I have a lot of embeds and it makes my main.js very cluttered. I want to put my embeds in another file to import from, but I can’t seem to figure out how to do this correctly. What am I doing wrong?

MY EMBED CODE: TEST.js

const Discord = require('discord.js')


 module.exports = (TEST) => {
          TEST(
               {
                  name: 'test1' ,
                  value: "```TESTING```",
                  inline: true,
                },
                {
                   name: 'test2' ,
                   value: "```TESTING```",
                   inline: true,
                 },
                 {
                   name:  "u200B" ,
                   value: "u200B" ,
                   
                 },
                 {
                   name: 'test4' ,
                   value: "```TESTING```",
                   inline: true,
                 },
                 {
                   name: 'test5' ,
                   value: "```TESTING```",
                   inline: true,
                 },
    
             )
          
    
    
          message.channel.send(embed).then(msg => {})
     
       })

MAIN JS CODE:

const Discord = require('discord.js')
const client = new Discord.Client()
const command = require('./command')
const config = require('./config.json')
const TEST = require('./TEST')


command(client, 'test' , (message) => {

 const embed = new Discord.MessageEmbed()

    .setTitle('Test')
    .setColor('#C69B6D')
    .addFields(TEST)
 
 message.channel.send(embed).then(msg => {})
 
})  

Advertisement

Answer

Why are you exporting the module as a function? You could just export it like objects and import that into the main.js

In TEST.js

Declare the TEST objects then use

module.exports.TEST = TEST;

And when you import in main.js you need to type TEST.TEST instead of TEST

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement