Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在discord.js中使用FS将richEmbed保存到文件?_Javascript_Node.js_Embed_Discord_Discord.js - Fatal编程技术网

Javascript 如何在discord.js中使用FS将richEmbed保存到文件?

Javascript 如何在discord.js中使用FS将richEmbed保存到文件?,javascript,node.js,embed,discord,discord.js,Javascript,Node.js,Embed,Discord,Discord.js,我在我的discord bot上创建了一个取消清除功能,它只需将最后一条批量清除的消息发送到常规通道即可恢复这些消息。为了做到这一点,我需要bot保存richEmbed(其中包含所有清除的消息),并将其保存在文本文件中,然后为了安全起见,我将使用simple-crypto.js对其进行加密。 当我尝试使用fs将richEmbed保存到文本文件时,问题就出现了,fs没有将richEmbed保存为UTF-8文本,而只是保存“[object]”,并且还出现了一个错误 DeprecationWarnin

我在我的discord bot上创建了一个取消清除功能,它只需将最后一条批量清除的消息发送到常规通道即可恢复这些消息。为了做到这一点,我需要bot保存richEmbed(其中包含所有清除的消息),并将其保存在文本文件中,然后为了安全起见,我将使用simple-crypto.js对其进行加密。 当我尝试使用fs将richEmbed保存到文本文件时,问题就出现了,fs没有将richEmbed保存为UTF-8文本,而只是保存“[object]”,并且还出现了一个错误

DeprecationWarning: Calling an asynchronous function without callback is deprecated.
以下是该部分代码:

var fs=require(“fs”);
fs.writeFileSync(“./unpurgeData.txt”,嵌入,{“编码”:“utf-8”});
…以下是整个取消敦促代码:

if(cmd.startsWith(“unpuke”)){
设x=10,//x的形式应该是0到25
嵌入=new Discord.RichEmbed().setTitle('Fecthed messages');
msg.channel.fetchMessages({limit:x})。然后(messages=>{
设arr=messages.array();//得到消息数组
对于(设i=0;i2048)str=str.substring(02045)+'…';
//如果内容超过了限制,你就删掉它
embed.addField(curr.author,str);//然后将其添加到嵌入
如果(i==arr.length-1){
msg.channel.send(嵌入);
var fs=要求(“fs”);
fs.writeFileSync(“./unpurgeData.txt”,嵌入,{“编码”:“utf-8”});
}
}
}).catch(控制台错误);
}

您的嵌入变量是一种对象类型。您可以通过执行以下操作进行检查:

console.log(typeof embed);
在本例中,您必须使用将对象转换为Mozilla文档中所述的JSON字符串

const text = JSON.stringify(embed);

然后在fs函数中,只需将嵌入替换为文本变量。

您的嵌入变量是一种对象类型。您可以通过执行以下操作进行检查:

console.log(typeof embed);
在本例中,您必须使用将对象转换为Mozilla文档中所述的JSON字符串

const text = JSON.stringify(embed);
然后在fs函数中,只需将嵌入替换为文本变量