【发布时间】:2021-02-24 04:30:42
【问题描述】:
我正在使用 Discord.js 库来创建一个不和谐机器人。每当我向文本通道发送嵌入消息时,它的宽度都会随着不同的数据而变化。
const celestialObject = new MessageEmbed()
.setColor("#F0386B")
.setTitle(
res.data.name == res.data.englishName
? res.data.englishName
: `${res.data.englishName} (${res.data.name})`
)
.attachFiles(attachment)
.setThumbnail("attachment://logo.png")
.addFields(
{
name: "```Density```",
value: res.data.density.toFixed(2) + " g/cm^3",
inline: true,
},
{
name: "```Gravity```",
value: res.data.gravity + " m/s^2",
inline: true,
},
{
name: "```Moons```",
value: res.data.moons ? Object.keys(res.data.moons).length : 0,
inline: true,
},
{
name: "```Mass```",
value: `
${res.data.mass.massValue.toFixed(2)}^
${res.data.mass.massExponent} kgs
`,
inline: true,
},
{
name: "```Escape Velocity```",
value: (res.data.escape / 1000).toFixed(1) + " km/s",
inline: true,
},
{
name: "```Orbital revolution```",
value: res.data.sideralOrbit.toFixed(2) + " days",
inline: true,
},
{
name: "```Rotation speed```",
value: (res.data.sideralRotation / 24).toFixed(2) + " days",
inline: true,
},
{
name: "```Radius```",
value: res.data.meanRadius.toFixed(2) + " kms",
inline: true,
}
)
.setTimestamp()
.setFooter(
"Generated by astronomia with Solar System OpenData API",
"https://api.le-systeme-solaire.net/assets/images/logo.png"
);
if (images[args[0]].description) {
celestialObject
.setDescription(`\`\`\` ${images[args[0]].description}\`\`\``)
.setImage(images[args[0]].link);
}
if (res.data.discoveredBy) {
celestialObject.addFields({
name: "```Discovered By```",
value: res.data.discoveredBy,
inline: true,
});
}
if (res.data.discoveryDate) {
celestialObject.addFields({
name: "```Discovered On```",
value: res.data.discoveryDate,
inline: true,
});
}
message.channel.send(celestialObject);
使用此代码,我得到以下结果。
如何每次都获得最大宽度?我查看了 discord.js 文档,但找不到任何东西。
【问题讨论】:
-
我不认为你可以,discord 嵌入总是占用他们需要的空间。不多。我认为这与移动设备上的不和谐有关。
标签: javascript api discord discord.js