【发布时间】:2021-03-04 00:53:39
【问题描述】:
我需要一种方法来获得嵌入的确切长度,以便检查它是否超出限制。因此,如果它确实超出了限制,它可以拆分为多个消息/嵌入。
【问题讨论】:
标签: python python-3.x discord.py-rewrite
我需要一种方法来获得嵌入的确切长度,以便检查它是否超出限制。因此,如果它确实超出了限制,它可以拆分为多个消息/嵌入。
【问题讨论】:
标签: python python-3.x discord.py-rewrite
如果我们查看 official Discord documentation 的丰富嵌入限制,我们可以看到总限制为 6000 个字符。
此外,所有
title、description、field.name、field.value、footer.text和author.name字段中的字符总数不得超过 6000 个字符。违反任何这些约束都将导致Bad Request响应。
但也有个别限制如下:
+-------------+------------------------+
| Field | Limit |
+-------------+------------------------+
| title | 256 characters |
| description | 4096 characters* |
| fields | Up to 25 field objects |
| field.name | 256 characters |
| field.value | 1024 characters |
| footer.text | 2048 characters |
| author.name | 256 characters |
+-------------+------------------------+
*见this announcementDiscord Developers server
因此,在许多情况下,您可能需要单独检查和处理所有这些限制。最后,这里是如何检查是否已达到总嵌入限制,这不检查上述单个限制。
# embed would be the discord.Embed instance
fields = [embed.title, embed.description, embed.footer.text, embed.author.name]
fields.extend([field.name for field in embed.fields])
fields.extend([field.value for field in embed.fields])
total = ""
for item in fields:
# If we str(discord.Embed.Empty) we get 'Embed.Empty', when
# we just want an empty string...
total += str(item) if str(item) != 'Embed.Empty' else ''
print(len(total))
【讨论】: