如果描述大于 2048 个字符,我正在尝试研究如何将 RichEmbed 拆分为两个单独的消息。
let embed = new RichEmbed()
.setColor(cyan)
.setAuthor(`Urban Dictionary | ${word}`, image)
.setThumbnail(image)
.setDescription(stripIndents`**Definition:**
${definition || "No definition"}
**Example:**
${example || "No example"}
**Upvotes:** ${thumbs_up || 0}
**Downvotes:** ${thumbs_down || 0}
**Link:** [Link to ${word}](${permalink || "https://www.urbandictionary.com/"})`)
.setFooter(`Requested by: ${message.author.tag} || Author: ${author || "Unknown"}`, message.author.avatarURL)
.setTimestamp()
message.channel.send(embed)
提前感谢!
首先将描述设置为变量。然后,您可以使用此答案中的正则表达式将描述拆分为 2,048 个字符长的段。最后,循环访问生成的数组,并发送包含原始字符串的每个段的嵌入。
示例代码:
const description = 'Lorem ipsum dolor sit amet.';
const split = description.match(/[sS]{1,2048}/g);
for (let i = 0; i < split.length; i++) {
let embed = new RichEmbed()
.setDescription(split[i]);
await message.channel.send(embed) // Async context needed to use 'await.'
.catch(console.error);
}