我在我的不和諧機器人上創(chuàng)建了一個取消清除功能,它通過將最后一批清除的消息發(fā)送到通用頻道來恢復(fù)它們。為了做到這一點,我需要機器人保存 RichEmbed(其中包含所有已清除的消息),并將其保存在一個文本文件中,然后我將使用 simple-crypto.js 對其進行加密以確保安全。當(dāng)我嘗試使用 fs 將 RichEmbed 保存到文本文件時出現(xiàn)問題,其中 FS 不會將 RichEmbed 保存為 UTF-8 文本,而是僅保存“[object Object]”,并且還會出現(xiàn)錯誤,DeprecationWarning: Calling an asynchronous function without callback is deprecated.這是代碼的那部分:var fs = require("fs"); fs.writeFileSync("./unpurgeData.txt", embed ,{"encoding": "utf-8"});...這里是整個 unpurge 代碼:if (cmd.startsWith("unpurge")) { let x = 10, // x should be form 0 to 25 embed = new Discord.RichEmbed().setTitle('Fecthed messages'); msg.channel.fetchMessages({ limit: x }).then(messages => { let arr = messages.array(); // you get the array of messages for (let i = 0; i < arr.length; i++) { // you loop through them let curr = arr[i], str = curr.content.trim(); if (str.length > 2048) str = str.substring(0, 2045) + '...'; // if the content is over the limit, you cut it embed.addField(curr.author, str); // then you add it to the embed if (i == arr.length - 1) { msg.channel.send(embed); var fs = require("fs"); fs.writeFileSync("./unpurgeData.txt", embed ,{"encoding": "utf-8"}); } } }).catch(console.error); }
如何在discord.js中使用FS將richEmbed保存到文件中?
Qyouu
2021-11-25 15:29:01