第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

Qyouu 2021-11-25 15:29:01
我在我的不和諧機器人上創(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);    }
查看完整描述

1 回答

?
www說

TA貢獻1775條經(jīng)驗 獲得超8個贊

您的嵌入變量是一種對象類型。您可以通過執(zhí)行以下操作來檢查:

console.log(typeof embed);

在這種情況下,您必須使用JSON.Stringify將您的對象轉(zhuǎn)換為 JSON 字符串,如 Mozilla 文檔中所述。

const text = JSON.stringify(embed);

然后在您的 fs 函數(shù)中,只需將embed替換為text變量。


查看完整回答
反對 回復(fù) 2021-11-25
  • 1 回答
  • 0 關(guān)注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號