如何调用一个单独的嵌入文件,然后命令它?

时间:2018-06-23 23:58:26

标签: javascript export embed

很抱歉这个问题。

我目前有一个Discord.RichEmbed存储在一个名为embed01.js的单独文件中 该文件存储在我的bots主目录中。

我想将其调用到bot中,然后放置一个命令以使用户能够看到它。

我正在努力理解出口职能,请寻求帮助。

在此示例中,我的前缀为“!”

典型的用户输入:!crew Bot会回复上述嵌入文件并将其显示给用户。

目前,我的代码位于main.js中,我希望将其保存在自己的文件中,并且仍然可以正常工作。

基本上,我希望下面的方法可以工作,但是要从文件中调用嵌入,而不是将代码保存在main.js中。

if(command === "crew") {
message.channel.send;
const embed = new Discord.RichEmbed()
.setTitle("Crewman Title goes here")
.setColor(0x663399)
.setDescription("Description here")
.setFooter("Footer goes here")
.setThumbnail("URL of image here")
.addField(`name part' , 'value part')


message.channel.send({embed});

我是一本公开的书,请随时向我询问任何可能需要的其他信息,以帮助我。

感谢您的时间和耐心!

1 个答案:

答案 0 :(得分:0)

使用module.exports导出单独文件的内容。

embed01.js:

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

const embed = new Discord.RichEmbed()   
// richembed content ... 
module.exports = (embed);

Main.js:

    //top of your main.js 
const embed = require('./embed01.js') 
    //your if query for your cmd
if(command === "help2") {
        let richembed = require('./embed01.js');
        message.channel.send({embed: richembed}); 
}