Javascript Discord.js嵌入宽度不可靠
我正在使用Discord.js库创建一个Discord bot。每当我向文本频道发送嵌入式消息时,其宽度会随着数据的不同而不断变化Javascript Discord.js嵌入宽度不可靠,javascript,api,discord,discord.js,Javascript,Api,Discord,Discord.js,我正在使用Discord.js库创建一个Discord bot。每当我向文本频道发送嵌入式消息时,其宽度会随着数据的不同而不断变化 const celestialObject = new MessageEmbed() .setColor("#F0386B") .setTitle( res.data.name == res.data.englishName ? res.d
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文档,没有找到任何东西。之所以会这样,是因为您使用的代码块太奇怪了,因为我也注意到了这一点,但不确定为什么会这样 如果你想阻止你的线路断开-
{
name: "```Orbital \n revolution```",
value: res.data.sideralOrbit.toFixed(2) + " days",
inline: true,
}
\n
打断了这条线,我在它周围使用了空格,这样在你的代码中就更清晰了你可以使用轨道\n卷积
一个我用来强制宽度的技巧:
embed.setFooter("\u3000".repeat(10/*any big number works too*/)+"|")
这段代码基本上设置了很多空格作为页脚,迫使discord为页脚加宽\u3000是“表意空间”的unicode,它是一个空格字符。(不能使用普通空格,因为discord只读取第一个空格。)另一种可能的方法是在消息中插入一个1px的大值透明图像(您可以从中生成一个)。我没有使用DiscordJS,但在简单的webhook格式中,它将类似于:
const embed={/。。。
图片:{
网址:'https://i.stack.imgur.com/Fzh0w.png'
}
}
在开发bot的过程中,您可以使用一些免费的服务,比如可视化地测试消息的外观
与建议的解决方案相比,使用此解决方案的好处如下:
- 请注意,如果尝试创建固定宽度的标题/作者姓名,则该空间也将超链接(+带下划线)
\u2800
(盲文模式空白)而不是表意文字空间,因为后者现在被Discord丢弃我不认为你可以,不和谐嵌入总是占据他们需要的空间。不多了。我想这与手机上也可以使用discord有关。不起作用。管道符号仅显示在我的左下角。