Discord.js将带有控制台的Javascript转换为用于Discord的嵌入



所以我现在正在开发一个机器人,当我查看api时,我得到了它如何工作的例子。

(async () => {
console.log(await bookwebsite.getHomepage(1))
})()
{
results: [ { bookId: 'web id',
thumbnail: 'thumbnail link',
title: 'book title' },
{ bookId: 'web id',
thumbnail: 'thumbnail link',
title: 'book title' },
{ bookId: 'web id',
thumbnail: 'thumbnail link',
title: 'book title' },
...
],
}

有人能引导我正确地将其从控制台日志脚本转换为在discord嵌入中运行吗?API警告NSFW

我不太确定您将控制台转换为嵌入是什么意思,但我猜您正试图将api中返回的数据格式化为Discord中的嵌入。

const bookwebsite = require('nhentai-js');
(async () => {
var data = await bookwebsite.getHomepage(1);
data = data.results.slice(0, 25);
if(!data) return message.channel.send('Failed to retrieve data from api. ')
// slices to avoid discord embeds going beyond 25 fields
var embed = new Discord.MessageEmbed()
.setTitle('Results found');
// For each the data that's received(after its trimmed)
data.forEach(d=>{
// For every object inside of data, it takes the name and sets it as a field title and sets the description of the field as the id and thumbnail link. 
embed.addField(`Name: ${d.title}`, `ID: ${d.bookId}nThumbnail: ${d.thumbnail}`)
})
// Embeds done, now need to send into the channel
message.channel.send(embed)
})()

如果您需要进一步的帮助,请在下面发表评论。

最新更新