简体   繁体   English

如何从另一个文件导入不和谐嵌入

[英]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.我有很多嵌入,这让我的 main.js 非常混乱。 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我的嵌入代码: 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:主要JS代码:

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 => {})
 
})  

Why are you exporting the module as a function?为什么要将模块导出为函数? You could just export it like objects and import that into the main.js您可以像对象一样导出它并将其导入 main.js

In TEST.js在 TEST.js 中

Declare the TEST objects then use声明 TEST 对象然后使用

module.exports.TEST = TEST;

And when you import in main.js you need to type TEST.TEST instead of TEST当你在 main.js 中导入时,你需要输入TEST.TEST而不是TEST

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM